Logging to the SharePoint ULS logs programmatically

18 06 2009

When writing SharePoint applications error messages should be handled appropriately, as well as displaying a message to the user it may be useful to log this message to the SharePoint 12 hive error logs. The SharePoint error logs sit in the following location of the server – 12 Hive\LOGS.

To write a message to the log directly from custom code you can use the Microsoft.Office.Server.Diagnostics.PortalLog class, simply reference the Microsoft.Office.Server.dll and use the following method:


The LogString method accepts a string so just pass in your exception message and your good to go. Additionally the ‘DebugWriteString()’ method works the same way as the above but allows you to specify the level of the item that you are logging (Critical, Error, Information or Verbose).

Hope this helps someone! 🙂




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: