Sitecore uses log4net as it's underlying logging framework, which means you can make use of any of the standard appenders. Although Sitecore have added a custom SitecoreLogFileAppender
appender, you can instead simply make use of the RollingFileAppender
and roll the log files based on date.
You can find samples in the log4net config examples section of the documentation.
Specifically with Sitecore, change the appender(s) to the following:
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender, Sitecore.Logging">
<file value="$(dataFolder)/logs/log" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<maxSizeRollBackups value="30" />
<datePattern value=".yyyyMMdd'.txt'" />
<staticLogFileName value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%4t %d{ABSOLUTE} %-5p %m%n" />
</layout>
<encoding value="utf-8" />
</appender>
Some specifics about the changes in the above configuration:
file
: The name of the file to log to. Note that we supplement this using below settings.
rollingStyle
: The format to roll each file on.
maxSizeRollBackups
: This has been set to 30 above, you can remove this node if you want. This value ensures that anyt logs older than 30 days get automatically deleted by log4net.
datePattern
: This sets the format of the date to roll the files on. Note that the file suffix is included here in single quotes. See this previous answer for more details.
staticLogFileName
: If set to true then the latest log file will always have the same name, but note that due to your file
value there is no file suffix.
The files will now be generated in format log.yyyMMdd.txt
in the same log folder as before and not be subject to having different files generated per application restart/app pool recycle.