Thursday, March 26, 2015

SharePoint 2013: Quick way to open all messages in ULS for a Correlation ID

SharePoint often gives a correlation ID which can be looked into ULS Logs to troubleshoot issues. Until recently, I used to go to individual servers and fire up the ULSViewer, to see the logs. Sometime, I used to access logs from other servers and open a multiple instances of ULS viewer. It was not always convenient to open multiple log files.

Recently, I came across a new PowerShell Command to Merge the log based on criteria given. Criteria could be Diagnostic Area, Category, Start Time, End time etc. For the purpose of this post, I’d use the correlation id.

So there is a Merge-SPLogFile Cmdlet to merge all log files from all servers and put it into a single file which can be opened into the ULS viewer.

Well, that’s good but I took it a step further to open the ULSViewer.exe and open the log file directly, saving myself some clicks!

Here is the script look like. It needs path to ULSViewer and prompt you for Correlation ID when you run the script.

   1:  $ulsViewerPath = "c:\Tools\ulsviewer\ulsviewer.exe"  
   2:    
   3:  $correlationId = Read-Host -Prompt "Enter Correlation ID"  
   4:    
   5:    
   6:  $fileName = [String]::Format("C:\temp\{0}-{1}.log", [DateTime]::Now.ToString("yyyyMMddHHmmss"), $correlationId);  
   7:  Merge-SPLogFile -Correlation $correlationId  -Path $fileName  
   8:    
   9:    
  10:  [Diagnostics.Process]::Start($ulsViewerPath,$fileName)  



So when I run this script with a correlation that SharePoint just gave me in UI, It saves the log file in C:\temp directory and automatically opens the ULS viewer with relevant log entries as shown below:


SNAGHTML208ce7a


Hope that helps you save some time.


No comments:

Post a Comment