X

Register now for unlimited access to Sitecore resources.


Already have an account? Log in now

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

Request a demo

It's easy to get started. Sign up for a personalised demo.

*{0} must be filled in.
*{0} must be filled in.
*{0} must be filled in.
*{0} must be filled in.
*{0} must be filled in.
*{0} must be filled in.
*{0} must be filled in.
Sitecore Blog: @sitecorejohn blog

All About Logging with the Sitecore ASP.NET CMS

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

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.

Comments

  • Free component for analyzing Sitecore logs:

    http://sdn.sitecore.net/resources/free%20modules/log%20analyzer.aspx

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

  • http://newguid.net/sitecore/2011/using-elmah-for-error-logging-within-sitecore/

    - John West
    December 04, 2012 at 7: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.

    http://marketplace.sitecore.net/en/Modules/Logger.aspx

    It can easily be extended if needed.

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

  • http://loggermodule.codeplex.com/

    - John West
    December 20, 2012 at 8: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="http://www.sitecore.net/xmlconfig/">
    <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 9:54 AM

  • http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2013/01/Cleanup-Log-Clutter-in-the-Sitecore-ASPNET-CMS.aspx

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

  • http://www.sitecore.net/Community/Technical-Blogs/Trevor-Campbell/Posts/2013/02/28-Days-of-Sitecore-Rocks-Log-Viewer.aspx

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

  • http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2013/03/Add-Requested-URL-and-Context-User-to-Error-Messages-in-Sitecore-ASPNET-CMS-Logs.aspx

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

  • This is a great logging library:
    http://www.kellermansoftware.com/p-14-net-logging-library.aspx

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

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