in SharePoint 2010

SharePoint 2010: Log to ULS from code

Note: Only supported in SharePoint 2010 and higher versions

Something every SharePoint developer asks for and here it is how you log to ULS from your code in SharePoint 2010. Below is a console app:


You need to add reference to Microsoft.SharePoint.dll. Very simple!

And here is our log from ULS Viewer:


The code uses the following classes:

1) SPDiagnosticsCategory

2) SPDiagnosticsService

P.S: I will update when I find out how to add a Correlation ID associated with the log entry.

Write a Comment


Time limit is exhausted. Please reload the CAPTCHA.

  1. So I just started with this and the console app works like a charm.. however when I try to write in my App – I don’t receive any errors, but it never writes!

    SPDiagnosticsCategory spdiagcat = new SPDiagnosticsCategory("Hello ULS", TraceSeverity.Verbose, EventSeverity.Verbose);
    SPDiagnosticsService diagSvc = SPDiagnosticsService.Local;
    diagSvc.WriteTrace(100, spdiagcat, TraceSeverity.Monitorable, "Writing to the ULS log is not happening…", null);