Sitecore Blog: @sitecorejohn blog

All About Logging with the Sitecore ASP.NET CMS | John West | Sitecore Blog

By John West, May 25, 2011 | Rating:  | Comments (10)

The Write to custom Sitecore log thread on the Sitecore Developer Network (SDN) forums prompted me to write this blog post containing or linking to everything I could find about logging with the Sitecore ASP.NET CMS.

Sitecore log files are critical to diagnosing issues with the solution. The Sitecore logs are completely separate from the IIS logs.

Sitecore uses Apache log4net for logging. You can use static methods in the Sitecore.Diagnostics.Log class, such as the Info() method, to write messages to the log. Each log entry indicates the thread, time, severitly level (INFO, WARN, ERROR, etc.) and a message. Most log entries appear in the file specified by the /configuration/log4net/appender named LogFileAppender defined in the web.config file, but Sitecore writes entries specific to WebDAV to the file specified by the <appender> named WebDAVLogFileAppender. The WebDAV logs are critical for diagnosing issues with WebDAV, but if you don't use WebDAV, you can disable the WebDAV logs as described in my blog post Cut Down WebDAV Logs. For more information about WebDAV, see the WebDAV Configuration manual on SDN.

Sitecore comes configured to generate one new log file each day the solution is active, with a file name containing the a date stamp. Sitecore may create additional log files each day with names containing a timestamp, such as if it finds the original log file locked after an ASP.NET restart. You might also nvelocity logs in the /data/logs folder within the document root of the web site (I don't know why they appear here instead of appearing in the same directory with the other logs), but I have never found anything useful in these logs.

With Sitecore 6, Sitecore merged the system and audit logs into a single file. The How to make Sitecore 6 write audit log to its own file entry in the Support Scrapbook on SDN explains how to separate these two types of log entries.

The How to prevent Sitecore from writing specific messages to the log file? entry in the Support Scrapbook on SDN explains how to prevent Sitecore from writing messages matching specific patterns to the log.

The Wake up log files entry in the Support Scrapbook on SDN explains how to resolve an issue with ASP.NET or log4net that prevents Sitecore from adding entries to the log file. I think this may apply on to very old versions of Sitecore or specific configurations.

On a busy development system, the directory containing log files can become cluttered. For a solution that automatically moves files from this directory, see my blog post Roll Sitecore Logs Automatically.

Sitecore's own Alex Shyba has written a few blog posts about logging with Sitecore:

Mark Ursino described how to log to your own files using the Sitecore logging system in his blog post Write to a Custom Sitecore Log with log4net. For more information, see Benjamin Vangansewinkel's Write you messages in a separated file.

I found it humorous that I got to use the file name logblog.txt while working on this post.

If you have any additional information about logging or know of any more resources on this topic, please comment on this blog post.

More posts All About the Sitecore ASP.NET CMS.


  • Free component for analyzing Sitecore logs:

    - John West
    September 10, 2012 at 4:10 AM


    - John West
    December 04, 2012 at 6:22 PM

  • Hi John. Thanks for the great post! We just released a shared source logger module on the Sitecore Marketplace that allows you to configure your log level and targets at runtime and lets you log to the browser console (Firefox + Chrome) via HTTP headers. It can easily be extended if needed.

    - Mark Lowe
    December 18, 2012 at 12:24 AM


    - John West
    December 20, 2012 at 7:43 AM

  • It looks like you can control how Sitecore removes log files by configuring attributes of the files/remove element with a value of $(dataFolder)/logs for the folder attribute within the /configuration/sitecore/scheduling/agent element named Sitecore.Tasks.CleanupAgent in the Web.config file. You can use a web.config include file such as the following to configure Sitecore to store log files for 35 days rather than the default of 7: <configuration xmlns:patch=""> <sitecore> <scheduling> <agent type="Sitecore.Tasks.CleanupAgent"> <files> <remove folder="$(dataFolder)/logs" pattern="log.*.txt"> <patch:attribute name="minAge">35.00:00:00</patch:attribute> </remove> </files> </agent> </scheduling> </sitecore> </configuration>

    - John West
    December 21, 2012 at 8:54 AM


    - John West
    January 29, 2013 at 10:17 AM


    - John West
    February 15, 2013 at 9:12 AM


    - John West
    March 29, 2013 at 2:50 PM

  • This is a great logging library:

    - asava samuel
    April 10, 2013 at 7:11 AM

  • Hi, We have a new requirement in logging logs. We are using Log4net to log data(type="log4net.Appender.SitecoreLogFileAppender, Sitecore.Logging") Our requirement is like in development we have four websites. We need to save all the logs of all the four websites in the server path for example S://Logging/Logs As all the websites logs to same path to differentiate the logs(i.e from which site the log came) we need to append appplication root folder name to log file name. I observed that we can append time to a log file name like "$(dataFolder)/logs/log.{date}.txt" /> Please suggest is there any way we can append application root folder name to log file name. For exampe the application folder name is SiteDev we want the log file names like log.SiteDev.{time}.txt Please provide valuable suggestions

    - Naveenreddy Kayithi
    November 25, 2014 at 11:03 AM

*{0} must be filled in.
*{0} must be filled in.
*{0} must be filled in.