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 (8)

  1. Since my previous post introduced one of my SharePoint Toolbox scripts, I thought I should share another

  2. In yesterday’s post , I noted the errors I encountered when trying to install Windows Server 2008 Service

  3. Ben McInerney says:

    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

  4. jjameson says:

    @Ben, great tip! Thanks for sharing.

    I’ve used Log Parser (available for download from microsoft.com) in the past to extract information from ULS logs. However, PowerShell appears to make it even easier with no additional download required (depending on your version of Windows).

    One of these days I’m really going to have to go out and get a book on learning PowerShell. I’ve resisted this in the past because the syntax is just so different from the language I typically work in (C#), but obviously PowerShell is getting more and more traction with each passing year.

    It looks like soon I’ll be reverting back to the sed/awk/grep-style of command-line operations I used to do back in my old Unix days 😉

  5. Dave Carver says:

    Thanks Jeremy! You need to come back to San Diego

  6. jjameson says:

    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?  😉