Logging to SharePoint 2010 ULS

Logging to the ULS has been vastly simplified in SharePoint 2010 the code below will add an entry to the log, this snippet was taken from inside a try catch block and has an Exception variable available which is used to populate the last two properties highlighted in bold. Replace “Your Category” with the name of the application/component you are working on and try and make it unique as this provides a string to search on in the logs to locate messages.

More information can be found on the SPDiagnosticsService in the msdn library http://msdn.microsoft.com/en-us/library/ee538293.aspx

SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(“Your Category”TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, exception.Messageexception.StackTrace);

Leave a Reply

Your email address will not be published. Required fields are marked *