Log4net rolling appender

Logs

A way to reduce log file size by telling log4net to create multiple files per day instead of one…

Versions used: Sitecore 8.1 rev. 151207 (Update-1).

Update/Warning: Using rolling appender, I occasionally experienced an issue where sitecore wouldn’t create log files after application pool recycle. Was not able to pinpoint if this was the issue but keep it in mind.

Have you ever had issues opening log files that are too big for text editors to process? I surely have.

Log4net can be configured to use a rolling file appender that creates multiple files once it reaches the maximum size per file set.

The following patch will delete default sitecore log4net appender and add a new one that tells log4net to create a log file every 50KB, per day. Note: pick a much bigger number but not too big that editors struggle to open the files.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<appender name="LogFileAppender" type="log4net.Appender.SitecoreLogFileAppender, Sitecore.Logging">
<patch:delete />
</appender>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="$(dataFolder)/logs/log" />
<appendToFile value="true" />
<datePattern value="'.'yyyyMMdd'.txt'" />
<rollingStyle value="Composite" />
<maxSizeRollBackups value="-1" />
<maximumFileSize value="50KB" /> <!-- KB, MB, GB -->
<preserveLogFileNameExtension value="true" />
<staticLogFileName value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%4t %d{ABSOLUTE} %-5p %m%n" />
</layout>
<encoding value="utf-8" />
</appender>

And this is the result:

Rolling logs


Please let me know what you think and/or if you can spot any errors.
/eom

Share