SharePoint ULS Logs Flooded with "Preserving template record with size..."

I was digging through my blog dashboard this morning and I came across this post that I started back in January but apparently never got it past "draft mode." I figured it was time to finish it off.

If you've been using Windows SharePoint Services (WSS) v3 or Microsoft Office SharePoint Server (MOSS) 2007 since the original release, you may have encountered the problem where, even with the out-of-the-box settings, the SharePoint Unified Logging Service (ULS) starts emitting thousands upon thousands of messages per minute, eventually filling up your hard drive with tens of gigabytes of log files, and ultimately "crashing" your server. Fortunately, the "completely fill my hard drive" feature has long since been removed and the ULS now stops logging before consuming every last megabyte of available space.

However, there are still some scenarios where the ULS logs can grow very quickly and while ULS eventually exerts some sense of self-restraint, it does manage to dump gigabytes of relatively useless information on your hard drive in a relatively short period of time.

Such is the case with my current MOSS 2007 development VM. Most every morning, I am greeted with the low disk space notification due to hundreds of thousands of "Preserving template record with size..." messages being generated over the course of the previous 24 hours, as shown in the following log excerpt:

 01/26/2009 02:45:35.43  OWSTIMER.EXE (0x0158)                    0x1424 Windows SharePoint Services    General                        0 Medium   Preserving template record with size 3301, use count 7, key ...
01/26/2009 02:45:35.43  OWSTIMER.EXE (0x0158)                    0x1424 Windows SharePoint Services    General                        0 Medium   Preserving template record with size 2225, use count 59, key ...
01/26/2009 02:45:35.43  OWSTIMER.EXE (0x0158)                    0x1424 Windows SharePoint Services    General                        0 Medium   Preserving template record with size 5728, use count 1, key ...
01/26/2009 02:45:35.43  OWSTIMER.EXE (0x0158)                    0x1424 Windows SharePoint Services    General                        0 Medium   Preserving template record with size 5731, use count 1, key ...
01/26/2009 02:45:35.43  OWSTIMER.EXE (0x0158)                    0x1424 Windows SharePoint Services    General                        0 Medium   Preserving template record with size 5732, use count 1, key ...

The good news is that the "Preserving template record with size..." issue only seems to occur when system resources are fairly tight; for example, on my VM with 2GB of RAM, running Visual Studio 2008, MOSS 2007, and SQL Server 2008 (even though I constrain SQL to 512MB of memory).

In other words, assuming you aren't trying to run your Production SharePoint environment on a single server with a mere 2GB of RAM, then this shouldn't be an issue.

The better news is that the "Preserving template record with size..." issue has been duly noted by the product team (in other words, a bug has been created) and it appears the logging level for this event will be changed in "O14" (i.e. the next version of SharePoint) to avoid incessantly spewing this message with the default logging settings.

As for addressing my daily "log purging" needs, I simply created the following script and dropped it in my SharePoint Toolbox folder (\NotBackedUp\Public\Toolbox\SharePoint\Scripts\Delete SharePoint Logs.cmd):

 @echo off
setlocal

set LogFolder=%ProgramFiles%\Common Files\Microsoft Shared\web server extensions\12\LOGS

echo This will delete all of the log files in the following folder:
echo    %LogFolder%
echo Are you sure you want to do this? (Press CTRL+C to exit)
pause

del /q "%LogFolder%\*.log"

Thus whenever I am greeted with the low disk space notification message, I simply open up my Toolbox, double-click this script, and then press Enter to quickly purge my log files. Once I do this, I see that the free space on my C: drive goes from 100-200MB of free space to around 1.4GB of free space.

Not exactly what I would call "elegant", but as I've repeatedly said before, I like to keep things simple.

Another useful tip that I wanted to pass along is effectively viewing very large text files (for example, to determine exactly why SharePoint is creating 1.3GB of log messages on a daily basis). While you can certainly try opening a 30-50MB file in Notepad, I certainly don't recommend it. Personally, I keep a copy of LtfViewr4U in my Toolbox for just such an occasion.

[Update 2009-06-02: As noted in the comments, this issue appears to be fixed in the April 2009 Cumulative Update for Windows SharePoint Services.]

Comments

  • Anonymous
    March 26, 2009
    PingBack from http://blog.a-foton.ru/index.php/2009/03/26/sharepoint-uls-logs-flooded-with-preserving-template-record-with-size/

  • Anonymous
    March 26, 2009
    Since my previous post introduced one of my SharePoint Toolbox scripts, I thought I should share another

  • Anonymous
    April 30, 2009
    This has now been fixed, see http://sharepoint.microsoft.com/blogs/fromthefield.

  • Anonymous
    June 02, 2009
    In yesterday's post , I noted the errors I encountered when trying to install Windows Server 2008 Service

  • Anonymous
    April 07, 2010
    Hi Jeremy, People may also want to keep their logs but purge those pesky entries so they can analyse the useful stuff. Here is my powershell one-liner to do just that: gc HWEB18-20100407-1507.log | where {$_ -notlike "Preserving template record with size"} | out-file presevationremoved.log This one cleans other simimlar guff: get-content HWEB22-20100408-0756.log | where {$_  -notmatch 'Generals+0s+Medium'} | out-file cleansed.log Of course you could wrap these in a scheduled task and use logic to get the latest minus one log file, but hey. Cheers, Ben

  • Anonymous
    April 11, 2010
    The comment has been removed

  • Anonymous
    April 30, 2010
    Thanks Jeremy! You need to come back to San Diego

  • Anonymous
    May 26, 2010
    Ah...beautiful San Diego...mmm...one of the few places besides Denver where I can actually picture myself living. Dave, I hope all is well with you. Give my best to Miles and George as well (hopefully you are all still working together). Want some help upgrading to SharePoint Server 2010?  ;-)