Logging to the 12 hive

When creating a Visual Studio workflow, webpart or other coded component for SharePoint, at times it makes sense to log events, notices, errors, etc to the 12 hive log. This is surprising easy to do, if you know the trick.
Visual Studio add reference dialog

Visual Stuido add reference dialog

 
First, you need to include a reference to Microsoft.Office.Server. The image to the left shows the dll to add.
 
Then, in your class have the following: using Microsoft.Office.Server.Diagnostics;
 
Then, where ever you want to log add the following:
PortalLog.LogString(“Message that I want logged);
 
 
And that is all there is to it. Now you can pass string values to the 12 hive logs.
Advertisements

About lelandholmquest

After serving in the Navy as a Reactor Operator on fast attack submarines, I earned both a Bachelor's and Masters in Information Technology from American InterContinental University and am currently working on my doctorate. I have a beautiful wife and two of the sweetest daughters a man could ask for. And I work for the greatest company: Microsoft. At Microsoft I work on the knowledge management system for Microsoft Services: Campus on Office 365.
This entry was posted in SharePoint Coding. Bookmark the permalink.

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