Create a configuration file with the following code:
View code
<exceptionHandling> <exceptionPolicies> <add name="Default Policy"> <exceptionTypes> <add name="All Exceptions" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="NotifyRethrow"> <exceptionHandlers> <add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" logCategory="Exception" eventId="100" severity="Error" title="Enterprise Library Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" priority="0" /> </exceptionHandlers> </add> </exceptionTypes> </add> </exceptionPolicies> </exceptionHandling>
The Code is as follows:
Namespace TMAC. utilities {// <summary> // exception handling operation class /// </Summary> public class exceptionhandlingutil {// default policy, consistent with the private const string defaultpolicy = "Default policy" defined in the configuration file "; /// <summary> /// record the exception log /// </Summary> /// <Param name = "ex"> </param> /// <returns> </returns> Public static bool handleexception (exception ex) {return handleexception (ex, defaultpolicy);} public static bool handleexception (exception ex, string Policy) {return exceptionpolicy. handleexception (ex, Policy );}}}