All About Logging with the Sitecore ASP.NET CMS

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.