Sitecore logging – Create new log file every day

Sitecore have since forever used Log4Net as it’s logging platform. Log4Net is nicely extensible and can be configured to log in many ways.

As per default, Sitecore is configured to start writing to a new log file every time Sitecore starts. And (in some versions of Sitecore) it will continue to write to that file until you restart Sitecore.

You can change that configuration. This configuration will create one and only one log file per day, even if the instance is restarted several times, or never:

<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
    <file value="$(dataFolder)/logs/log" patch:instead="file" />
    <rollingStyle value="Date" patch:instead="rollingStyle" />
    <preserveLogFileNameExtension value="true" patch:instead="preserveLogFileNameExtension" />
    <datePattern value="'.'yyyyMMdd'.txt'" patch:instead="datePattern" />
    <staticLogFileName value="false" patch:instead="staticLogFileName" />

Differences from standard Sitecore configuration are:

  • rollingStyle have been changed from Size to Date.
  • The folder name and file date pattern is now split. Property “file” contains the folder and file prefix, and the datePattern property contains the file suffix.
  • staticLogFileName is false, allowing Log4Net to use the datePattern property as file name.

When the configuration is added to a logging.config file, the resulting merge is this:

<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" patch:source="logging.config">
    <file value="$(dataFolder)/logs/log" patch:source="logging.config"/>
    <appendToFile value="true" patch:source="logging.config"/>
    <rollingStyle value="Date" patch:source="logging.config"/>
    <maxSizeRollBackups value="-1"/>
    <maximumFileSize value="10MB"/>
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%4t %d{ABSOLUTE} %-5p %m%n"/>
    <encoding value="utf-8" patch:source="logging.config"/>
    <preserveLogFileNameExtension value="true" patch:source="logging.config"/>
    <staticLogFileName value="false" patch:source="logging.config"/>
    <datePattern value="'.'yyyyMMdd'.txt'" patch:source="logging.config"/>


About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in Sitecore 6, Sitecore 7, Sitecore 8, Sitecore 9 and tagged , , . Bookmark the permalink.

3 Responses to Sitecore logging – Create new log file every day

  1. João Neto says:

    Thanks for sharing. Great idea! Helpful if you want to tail de log file with Notepad ++ or another tool.


  2. Pingback: Sitecore and Application Insights – How to remove 90% of all log lines without sacrificing traceability | Brian Pedersen's Sitecore and .NET Blog

  3. Kim Frandsen says:

    Thanks for sharing. I would just like to point out that if the application pool uses overlapped recycles (which is IIS default), then this will not work, because if you have daily recycles or after deployments, then logs will be missing for the rest of the day because the “old” application pool locks the log file while the “new” application pool is trying to write to it.
    Do you have an opinion on how much effect overlapped recycles has on performance or if it is OK to disable it?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.