Friday, October 12, 2012

Usage of Merge-SPLogFile in SharePoint

We can setup our SharePoint as a multi server farm. Although it is best to distribute workloads among different servers, It can be very painful to debug errors.

Let’s assume we have a SharePoint farm with 3 servers (WFE, App, DB). For an example, let’s say suddenly we get an error while opening a excel document. What do we normally do ?

If the error message is not self-explanatory we will use ULS logs.There are very helpful ULS log readers available. (ULS Viewer is my favourite). First we will log in to WFE and investigate the error using ULS logs and relevant Correlation Id.

image
If the “Excel Services” service application is deployed in App server we might need to get ULS logs from that server as well. If we have tens of servers in our farm we will be in a great trouble. Are we going to remote login each and every server to debug the error?
There is a far better solution. There is a PowerShell cmdlet called Merge-SPLogFile. Using that we can get all log entries from all servers. In the above scenario where we have an issue and we know the correlation id we can use something like below to generate a log file compiled from each server in the farm.

image
Then we can open the CustomLog.log file using ULS Viewer to check all related information from each server.

image
Is this the only usage from Merge-SPLogFile command?
Not really. We can do following using the command. (and there are more use cases as well)
  • Get a summary of all activity compiled from all servers in last hour
Merge-SPLogFile -Path "D:\Logs\FarmMergedLog.log" -Overwrite
  • Get a summary of all activity compiled from all servers for a given log area in last hour(ex.: Search) 
    Merge-SPLogFile -Path "D:\Logs\FarmMergedLog.log" -Overwrite -Area Search
I hope you got some idea about this PowerShell cmdlet.