Monday, January 24, 2011

Troubleshooting in SharePoint 2010 - ULS Logs : Correlation ID

I am sure all of you have worked with Logs to figure out what is happening within your SharePoint application. However, there are cases where you will need to know what is happening within the SharePoint services, that is causing a failure in your application. Especially when you see a message with a Correlation ID that is a pointer to SharePoint logs. 
SharePoint 2010 provides interfaces to Read/Write into the common logging system.

All the SharePoint logs are by default created under "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS" with file names like "$machine$-$date$-$time$.log"

You can configure what needs to be logged in the Central Administration > Monitoring > Reporting > Configure Diagnostics Logging.
Select the Service you are interested in with the required sub category and set the "least critical event to report to the trace log" to the level you intend to monitor. Medium would suffice in most of the case.

You can download a codeplex solution to make your life easier in reading these logs from
The Viewer is self explanatory, just load the log file from the LOGS folder of 14 hive and you are all good to go. I used the Notifications List & Filters very often to see a snap shot of the most critical errors.
Use the Toggle Correlation Tree icon on the top right to see a list of Correlation IDs. 
Ctrl + Shift + I can be used for monitor a particular Correlation ID.

Good news is that SharePoint allows you to write your log messages into it's own framework so that you do not have to maintain two different logs one for your application and another for SharePoint.

Code to write to the SharePoint ULS Logs is as below:

public static void Write(string message)
{
    SPDiagnosticsService logger = SPDiagnosticsService.Local;
    logger.WriteTrace(0,
        new SPDiagnosticsCategory("MyApp",
            TraceSeverity.Monitorable,
            EventSeverity.Error),
            TraceSeverity.Monitorable,
           "Application Message : {0}",
           new object[] {message});
}

That's it for now. Good luck on your next troubleshooting!

No comments:

Post a Comment