Click here to Skip to main content
15,894,646 members
Articles / Web Development / ASP.NET

Handling Error Centrally in a SharePoint Application

Rate me:
Please Sign up or sign in to vote.
4.21/5 (11 votes)
20 May 2008CPOL4 min read 85.1K   596   22  
An article on handling errors centrally in a SharePoint application, using IHttpModule.
<configuration>

	<configSections>
		<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
	</configSections>

	<loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
		<listeners>
			<add fileName="C:\MySharePointSite.log" header="----------------------------------------"
						 footer="----------------------------------------"
						 formatter="Text Formatter"
						 listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
						 traceOutputOptions="None"
						 type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
						 name="FlatFile TraceListener" />
		</listeners>
		<formatters>
			<add template=	"Code:{title}&#xD;&#xA; 	Timestamp: {timestamp}&#xD;&#xA; 
		    Message: {message}&#xD;&#xA; 				Category: {category}&#xD;&#xA; 
		    Priority: {priority}&#xD;&#xA;				EventId: {eventid}&#xD;&#xA;
			Severity: {severity}&#xD;&#xA;				Machine: {machine}&#xD;&#xA;
			Application Domain: {appDomain}&#xD;&#xA;	Process Id: {processId}&#xD;&#xA;
			Process Name: {processName}&#xD;&#xA;Win32 	Thread Id: {win32ThreadId}&#xD;&#xA;
			Thread Name: {threadName}&#xD;&#xA;		
			Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
				  name="Text Formatter" />
		</formatters>
		<categorySources>
			<add switchValue="All" name="General">
				<listeners>
					<add name="FlatFile TraceListener" />
				</listeners>
			</add>
		</categorySources>
		<specialSources>
			<allEvents switchValue="All" name="All Events" />
			<notProcessed switchValue="All" name="Unprocessed Category" />
			<errors switchValue="All" name="Logging Errors &amp; Warnings" />
		</specialSources>
	</loggingConfiguration>

</configuration>


<system.web>
	<httpModules>
		<add name="MyErrorHandler" type="CentralErrorHandler.ErrorModule, CentralErrorHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=06a3e095a0c5fc38 " />
	</httpModules>
</system.web>


<appSettings>
	<add key="CustomErrorPagePath" value="http://MySharePointSite/MyErrorHandler.aspx" />
</appSettings>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Gen-i, Australia
Australia Australia
Expertise area: ASP.NET, C#, Microsoft Office SharePoint 2010 & 2007, Web Service, Windows-based Applications etc.

Blog: http://mydevdiary.blogspot.com/

Comments and Discussions