SharePoint Logging and Exception Handling Solution

Overview
The RDA Logging and Exception Handling Solution demonstrates how to use standard ASP.NET techniques to incorporate Logging and Exception Handling in a SharePoint web-site.

Logging
Custom .NET SharePoint code such as Web Parts, Event Handlers, Feature Receivers, etc. can use the Trace class (in the System.Diagnostics namespace) to write to different Trace Listeners. This solution includes A Log class that provides helper methods around the standard Trace methods to write different types of entries such as Error, Information and Warning to the Trace Listeners that can be defined in the web.config. A custom Web Application level Feature with a custom Feature Receiver deploys the relevant changes to the web.config file using the SPWebConfigModification class. The custom Feature Receiver uses a recursive method to synchronize changes from the ConfigChanges.xml file into the web.config file.

Exception Handling
For Global Exception handling, the HttpApplication class provides the Error event that is raised for any unhandled exceptions. This solution includes a custom Global.asax file that handles the Error event to catch and log all Exceptions that occur in a SharePoint web-site. A custom SharePoint Job deploys the Global.asax file to all the SharePoint servers in the farm. A custom Web Application level Feature with a custom Feature Receiver creates an instance of the Job on each SharePoint server when it is activated.

Testing
To test the Logging and Exception Handling, this solution includes an Exception Web Part that causes a divide by zero error when it is rendered. The EventLogTraceListener writes the exception to the Event Log as defined in the web.config file.

Putting it Together
The Visual Studio solution uses WSPBuilder to create a SharePoint solution called RDA.LoggingExceptionHandling.wsp that consists of the following:
  • RDA.LoggingExceptionHandling.dll: This consists of all the .NET code.
  • RDA Logging and Exception Handling Application Feature: This is the Web Application level that should be activated to deploy the web.config changes and the custom Global.asax file.
  • Exception Web Part: Used for testing the functionality of the Solution.
This feature is part of the RDA Collaboration Tools and Utilities release.

Last edited Aug 3, 2008 at 11:51 PM by ggalipeau, version 3

Comments

No comments yet.