Troubleshooting: Collecting Verbose ULS logs

Working with Microsoft on the one of the issues we were asked to provide verbose ULS logs. Having the ULS logs in verbose mode might take a lot of disk space. Here is a simple solution: enable the verbose logging only for the period of time to reproduce the issue and switch it back to default level when done. PowerShell to the rescue: the following script will change the ULS log level to verbose and pause while you can reproduce the issues that is being troubleshooted. Just press the enter button after that and it will switch the log level to default (Information). If your default log level is different from Information modify the script accordingly. The script will generate Merged ULS log for the period between the start of the script and the time you pressed the Enter button to continue.

####################################################################################################
#
#  Author.......: David Shvartsman
#  Date.........: 06/27/2018
#  Description..: Troubleshooting: Collecting Verbose ULS logs
#
####################################################################################################
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
CLS
$startDate = (Get-Date -format "MM/dd/yyyy HH:mm:ss")
set-sploglevel -traceSeverity verbose
pause

$endDate = (Get-Date -format "MM/dd/yyyy HH:mm:ss")
Clear-SPLogLevel
$logfile = "d:\temp\ULSLogFileName.log"
if (test-path $logfile) {
          Remove-Item $logfile
}

Merge-SPLogFile –Path $logfile –StartTime $startDate –EndTime $endDate

####################################################################################################

That was another page in the Chronicles of SharePoint Bits, happy scripting!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

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

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.