Home > SP2010 > Take control of your log files

Take control of your log files

Everyone knows about SharePoint’s ULS logs, these are written by the SharePoint tracing service.

image

To the location set in Central Admin –> Monitoring –> Configure Diagnostic logging 

image

image

You also have a couple of options to control the number of logs created and /or the amount of space used making SharePoint log space friendly, you should be writing the logs to a non-system drive.

But what about IIS ?  In IIS logging can either be on or off, and you can change their location, but that’s about it.

From the IIS console select Logging and open the feature

image

From here you can set the location for the IIS logs, a location set here will be used for all the sites on the server, and it should be on a non-system drive.

image

The IIS log location will look something like this, with a number of sub-folders, one for each web application.

image

the folder names (after the W3SVC) will tally with web site id shown in IIS

image

each folder will contain a number if log files, normally one created per day.

image

This folder names will be the same on all your servers as the site ids are replicated, the only problem with this is that the IIS logs never get cleaned-up. To help address this I have written a quick PowerShell script, that will delete log files over 30 days old.

 

# PS script used to delete IIS logs from sub folders
# set the location to start from
# $location = "D:\logs\iis" use the lines below to read in a location from the command line
$location = $args[0]
if (! $location)
{$location= Read-Host "Enter location to cleanup"}
# get a reference to each file from each subfolder by using the -recursive switch.
foreach ($File in get-childitem $location -Recurse -Include *.log)
# check the lastwrite time and delete if necessary
{if ($File.LastWriteTime -lt (Get-Date).AddDays(-30))
     {del $File}}

The location can either be set in the script or read in when you run it, the –Recuse argument causes Get-Child item to walk through nested folders, with the –Include argument putting a filter on log files, with the –30 value specifying how old a file has to be in days to be deleted.

This can wrapped in a simple batch file and called from a weekly scheduled task to keep your IIS files under control.

Advertisement
Categories: SP2010 Tags: , ,

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: