Back to Insights

Configuring SharePoint 2010 diagnostic logging

With SharePoint 2010, there is a lot you can do using PowerShell. Although settings can be configured using SharePoint Central Administration, using PowerShell provides several advantages. It provides a foundation to create reusable scripts for your configuration.

Here is a simple example on how configure diagnostics logging:

$path = "C:\Logs\MSS\Diagnostics"
#Check if the directory exists and create it otherwise
if (!(Test-Path $path))
	New-Item $path -Type Directory

#Configure SharePoint 2010 diagnostics logging
Set-SPDiagnosticConfig -DaysToKeepLogs 5 -LogLocation $path -LogMaxDiskSpaceUsageEnabled -LogDiskSpaceUsageGB 5 

This script sets the diagnostics logging settings to keep logs for 5 days, for a maximum of 5 gigabytes, and to store the log files in the folder "C:\Logs\MSS\Diagnostics".