Technology Toolbox

Your technology Sherpa for the Microsoft platform

Jeremy Jameson - Founder and Principal

Search

Search

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

Note
This post originally appeared on my MSDN blog:

Since I no longer work for Microsoft, I have copied it here in case that blog ever goes away.

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

  1. # re: SharePoint ULS Logs Flooded with "Preserving template record with size..."

    April 30, 2009 5:08 PM
    mrwhitey

    This has now been fixed, see http://sharepoint.microsoft.com/blogs/fromthefield.

  2. # re: SharePoint ULS Logs Flooded with "Preserving template record with size..."

    April 7, 2010 12:31 PM
    Ben McInerney

    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 'General\s+0\s+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

  3. # re: SharePoint ULS Logs Flooded with "Preserving template record with size..."

    April 11, 2010 6:59 PM
    Jeremy Jameson
    Gravatar

    @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 ;-)

  4. # re: SharePoint ULS Logs Flooded with "Preserving template record with size..."

    April 30, 2010 1:40 AM
    Dave Carver

    Thanks Jeremy! You need to come back to San Diego

  5. # re: SharePoint ULS Logs Flooded with "Preserving template record with size..."

    May 26, 2010 3:25 AM
    Jeremy Jameson
    Gravatar

    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?  ;-)

  6. # infoblog » SharePoint ULS Logs Flooded with “Preserving template record with size…”

    March 25, 2009 8:13 PM
    blog.a-foton.ru
  7. # Script to Restart SharePoint Services

    March 25, 2009 8:34 PM
    blogs.msdn.com
  8. # Reclaiming Disk Space After Installing Service Pack 2

    June 1, 2009 8:40 PM
    blogs.msdn.com

Add Comment

Optional, but recommended (especially if you have a Gravatar). Note that your email address will not appear with your comment.
If URL is specified, it will be included as a link with your name.

To prevent spam from being submitted, please select the following fruit: Grapes

Watermelon
Apple
Cherries
Pear
Grapes
Strawberry
 
Please add 2 and 6 and type the answer here: