Can log4net entries be queried?

I know I can write to the EventLog and query it. I would like to implement the ability for the user to select a menu item that will query all Warning and Error msgs connected to my app and send those to me.

I can do all of this with C# and the Event Log. Is the same possible with log4net? Obviously I can log Warning and Error msgs with log4Net, but can I then query the log4Net "database"? Or are the log msgs not even saved?

Upvotes: 2

Views: 2689

Answers (3)

Ken Cenerelli
Ken Cenerelli

Reputation: 520

You can choose to use different file appenders in log4net to write to different log files. I currently have one for errors and one for trace logging so that I can log my code's activity.

Check out this link for examples on how to implement this - http://geekswithblogs.net/ontheledge/archive/2009/09/23/logging-with-log4net.aspx

Also, if you wish to parse your text log files see this old StackOverflow question regarding parsing log4net files for error codes - Parse log files programmatically in .NET

Upvotes: 2

Arran
Arran

Reputation: 25066

You can set log4net up to log to a database table instead - then you could query it like you would any database object:

http://logging.apache.org/log4net/release/config-examples.html

Upvotes: 1

evanmcdonnal
evanmcdonnal

Reputation: 48114

With Log4net you have several options of how to write the logs. If they're text files, you could parse them and send the data (obviously can't query a text file).

However, you can log to the event log with log4net so you could retain your event log implementation for querying and just log to there with log4net.

Edit: The following link has a list of different things you can log to. You can log to a database. You can even send your output to a remote log if you want to remove the menu options altogether and just have all log output sent back to your server. http://logging.apache.org/log4net/release/features.html

I've only used log4net for logging to text files and the Windows event log. Both were easy and straight forward. I would recommend it.

Upvotes: 1

Related Questions