A few months ago I made a most about log4net. Like most I was having some trouble getting things up a running. From that time I've now got a standard logging class that I include in every project I write. At first all I wanted was the ability to log something and have the ability to change the logging levels without recompiling. Log4net definatley does just that plus a whole lot more.
I'm using a modified version of Nauman Leghari's class that he provided for everyone to download; it is an excellent framework to start with. Since most have trouble with their config files more than the classes themselves I'm going to post my config file that works nicely with log4net version 1.2.0.30714 (1.2 beta 8).
I have two appenders:
LogFileAppender - This is the basic rolling log file. Its my primary source for all logging and will log any message that is at the level set in the root element. A new log will be created after it reaches 5MB and 10 of those will be kept. All of this is customizable but I've found these to be about right.
SmtpAppender - This is about as advanced as I get (so far) with my logging. This appender will send an email containing the message just logged along with the last 512KB of messages in the buffer. This is helpful to provide context to the actual error message. Even though the root logging level is INFO, the threshold element sets the level that the message must be equal to or greater than to be sent using this appender.
Config file can be downloaded here log4netconfig.zip.
Message formatting:
I like a straight forward message that is clean and precise. There is a lot that can be logged but I basically want the date/time/level/custom message and exceptions.
Example output:
|
11-04-2005 08:58:41 DEBUG [cam/default] was deleted from the Database. 11-04-2005 08:58:41 ERROR Invalid Argument Exception: System.ArgumentException Message: Invalid arugument was provided. Only accepted argument is 'validate'. Source: hvmscc at Company.HVMSContentConverter.Converter.Main(String[] args) 11-04-2005 08:58:41 INFO 1 error(s) occured during process. |