Sitecore Blog: @sitecorejohn blog

Roll Sitecore Logs Automatically

By John West, October 26, 2010 | Rating:  | Comments (3)

/w3upload/site graphics/technician.jpg

This blog post describes how you can configure the Sitecore ASP.NET CMS to automatically move old log files to a backup subdirectory when the application initializes.

Sitecore writes diagnostic messages to a log file. When possible, Sitecore writes to a log file named after the system date, such as log.20101026.txt for the 26th of October, 2010.

If Windows does not immediately release its lock on the Sitecore log file after the application restarts, Sitecore creates a new log file, such as log.20101026.105221 on the 26th of October, 2010, around 10:52:21 AM. I seem to get a new log file each time I compile my project.

I generally only care about the latest log file, but I want to keep the old log files in case I need to refer to them at some point. If I recompile repeatedly, the log directory gets cluttered.

To make it easier for me to work with Sitecore logs, I wrote a processor for the initialize pipeline to move old logs to a backup directory. You can download the code here, but note that I did not test strenuously.

To cause Sitecore to invoke the processor, add its signature at the end of the <initalize> pipeline defined in the web.config file:

<processor type="Sitecore.Sharedsource.Pipelines.Loader.RollLogs, assembly" />

Over time, this could create many subdirectories under the logs subdirectory, but subdirectories are easier to sort and remove by hand.

You might also be interested in my previous blog post, Cut Down WebDAV Logs.

Tags: Architecture, Infrastructure, API

Comments

  • Just a small note on this. If you are using the Advanced System Reporter, some of the reports in it are using scanners that inherit from LogScanner, which, as the name suggests, scans the logs.
    It will only scan the logs from the normal Sitecore logs directory, so if you're moving your log files to a backup directory, your Reports mightn't be very helpful.

    - Sean Holmesby
    July 06, 2011 at 2:29 AM

  • You attached the wrong file to your download link. Your link downloads ResetFields.cs

    - Dwight Sands
    April 10, 2012 at 12:22 PM

  • @Dwight: Thanks for reporting that, sorry. I updated the link.

    - John West
    April 10, 2012 at 1:21 PM

*
*
*

Learn More with Sitecore

Newsletter
*

Thomas Cook | Read Case Study >

Sitecore gives our customers a compelling, interactive experience and, as a result, our sales have increased.

- Wim Vermaesen, Thomas Cook