SharePoint - Logging to ULS in SharePoint 2010
When developing custom components for SharePoint, be it simple or complex, it is a good practice to log all the activities made by the solution. It is of great help during debugging and maintaining the code. SharePoint 2010, via its object model, let's us access the diagnostic services and add custom messages to the log files. Here is a quick example. In this case we are trying to access a list named MyList, which does not exists in the site. So an exception will be thrown. using (SPSite site = new SPSite("http://site/")) { using (SPWeb web = site.OpenWeb()) { try { SPList list = web.Lists["MyList"]; } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("My Category", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, ex.Message, ex.StackTrace); } } } And here is what we get i...