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:

logtouls_code

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

And here is our log from ULS Viewer:

llogtouls_ulsviewer

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.


Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading





Creative Commons License
Chaks' Corner Blog by Chakkaradeep Chandran is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
Based on a work at www.chakkaradeep.com.
Permissions beyond the scope of this license may be available at http://www.chakkaradeep.com.