Configuring Log4net so the sysop stays happy

Maintaining larger solutions is always hard, as unexpected occur(for example, your server contains a 300GB HDD for logging which is filled after 2 week of running).. I’ve seen the same problems. Today I’ll discuss how to configure Log4net in the way the system operator stays happy. This should become a part of the deployment proces or even before ‘go live!/finishing touch’ of the project.

Looking at the web.config(SC5.3) you will find the following node:

<log4net>
<!– LOGGING SETTINGS
The file element defines the location of the log files. This location must
be the same as the setting in LogFolder. The file element is a relative or
absolute path that always uses slashes (/) as separators. A valid file
element for a relative path would be:
<file value=”/data/logs/log.{date}.{processid}.txt” />
A valid element for an absolute path would be:
<file value=”C:/inetpub/wwwroot/data/logs/log.{date}.{processid}.txt” />
For further information refer to the Log4Net documentation.
–>
<appender name=”LogFileAppender” type=”log4net.Appender.SitecoreLogFileAppender, Sitecore.Logging”>
<file value=”D:/NET Development/Sitecore Projects/Sitecore 5.3 Playground/data/logs/log.{date}.txt”>
</file>
<appendToFile value=”true”>
</appendToFile>
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%4t %d{ABSOLUTE} %-5p %m%n”>
</conversionPattern>
</layout>
</appender>
<root>
<priority value=”INFO”>
</priority>
<appender-ref ref=”LogFileAppender”>
</appender-ref>
</root>
</log4net>

Log file names:

The first thing what show up is the way logfiles are created. Sitecore provides a little feedback on it where they explain you can easily add paramaters to the names of the files:

{date} – Date in YYYYMMDD-format
{procesid} – Return the WindowsProcesId which is writing. Could be usefull when you’ve got conflicts on locked files.
Other patterns can be found here: http://logging.apache.org/log4net/release/sdk/log4net.Util.PatternString.html

AppendingtoFile?

Yes, that’s the question, append to file or overwrite. As Sitecore produces so many lines of logs, and most of the time, jsut one logline is useless: do mot change this.

A line of logging:

A single line of logging is formatted by the layout/conversionPattern-node. For a full description how to configure this section, take a look at the detailed API dump of Log4Net.

Priority based logging:

Normally, you can define the priority of a the lines you want to be logged, as specified in the priority-node, but so far I haven’t been able to change it to any other value. I’ve tried ‘WARN’ and ‘ERROR’ so far. Does someone have a clue why changes to this attribute only result in an empty logfile? 

Resources on the web:

One thought on “Configuring Log4net so the sysop stays happy”

Comments are closed.