Writing a message to the SharePoint 12 hive log

Today I needed a fallback to my implementation of the Enterprise Library Logging Block. In other words, I needed to be able to log that something went wrong when trying to log through EntLib.
I ended up with this little piece of code that writes the message to the logfile(s) in the 12 hive/Logs catalog:

public void Log(string message)
{
    try
    {
        // Log message through EntLib
    }
    catch(Exception e)
    {
        PortalLog.LogString(
            "{0}: An error occured while writing message through EntLib. \nThe error was: {1}",
            DateTime.Now.ToString(), e);
    }
}

PortalLog is located in the Microsoft.Office.Server.Diagnostics namespace found in in the Microsoft.Office.Server.Diagnostics.dll, i.e. it only works on a MOSS installation.

 

Nothing new and innovative, I know…but helpful.

  1. Leave a comment

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: