SharePoint Logging Library

Rating:        Based on 4 ratings
Reviewed:  4 reviews
Downloads: 1185
Released: Jul 22, 2009
Updated: Jul 23, 2009 by sharepointholic
Dev status: Stable Help Icon

Recommended Download

Source Code SharePoint Logging Library Source Code
source code, 304K, uploaded Jul 22, 2009 - 1023 downloads

Other Available Downloads

Application SharePoint Logging Library DLL
application, 5K, uploaded Jul 22, 2009 - 162 downloads

Release Notes

In my article "Simplifying SharePoint Debugging By Creating the Troubleshooting Toolbox", I have stated the following :
"I’d also like to point out that you can write code that incorporates logging to MOSS logs. Writing to the same trace log alleviates the need for developers to log their development information in other places such as the Windows Event Log, which is more commonly used by system administrators."

Unfortunately this comes with 3 gotchas :

1)You cannot set the log event level (e.g. low, medium, and critical) as it’ll always display the error level in the trace logs as High.

2)Also you cannot control the trace category as it'll always display the category as "General".

3)The logger is located in 12\ISAPI \Microsoft.Office.Server.dll and therefore it’s only available with the MOSS install, not WSS 3.0.

What if you need to write into SharePoint trace logs while having full control on the error level and category?

Enter SharePoint Logging Library !

1) Download the "SharePoint Logging Library" from CodePlex.
2) Add a reference to AymanElHattab.SharePoint.Logging.dll .
3) Add a using statement to AymanElHattab.SharePoint.Logging namespace.
4) Use the library as follows :

SharePointLogger.LogWarning("Hello SharePointers");
SharePointLogger.LogInformation("x = " + x);
SharePointLogger.LogMessageWithSeverityAndCategory("Hi", SharePointLogger.TraceSeverity.High, "My Category");

5) Get your code executed , then open the trace logs.

As you might have noticed from investigating the trace logs:

1) You can call the public methods SharePointLogger.LogStartOfMethod() and SharePointLogger.LogEndOfMethod() for writing to SharePoint Trace Logs .You don't need to pass the method or class name, this will be automatically logged by Reflection as shown in the figure above : "Beginning of NameSpace.ClassName.MethodName Method".

2) You can control the severity and the category when you use the LogMessageWithSeverityAndCategory() Method.

3)"General" is the default category when you use the methods that doesn't accept a parameter for the category.

4) You can log exceptions and their stack traces by passing the exception object to the public LogException() Method.

For more info refer to :

Reviews for this release

I love your work, excellent library!
by keandavid on Nov 1, 2009 at 5:11 PM
I like the way the library detects the method and namespace, , keep it up
by RothSharp on Nov 1, 2009 at 4:58 PM
very useful, are you willing to upgrade to SharePoint 2010
by abdoullaelgazzar on Nov 1, 2009 at 4:52 PM
Easy to use, works great. Thanks for doing this.
by Quiziqal on Oct 14, 2009 at 8:48 PM