Search This Blog

Tuesday, January 10, 2012

Writing Errors to Sharepoint Logs

Sharepoint 2010 has provided us with an API for writing to the default ULS log file in which Sharepoint writes its logs. To do this you can make use of the SPDiagnosticsService which is available in
Microsoft.SharePoint.Administration namespace.



try
   {
    //execute your code
   }
   catch (Exception ex)
   {
    SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("YourCustomKey", TraceSeverity.Medium, EventSeverity.Error), TraceSeverity.Monitorable, ex.Message, ex.StackTrace);
    }
}

No comments:

Post a Comment