Create a configuration file with the following code:
| The code is as follows: |
Copy 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 = "policyrethrow">
<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:
| The code is as follows: |
Copy code |
|
Namespace Tmac. Utilities
{
/// <Summary>
/// Exception handling operation
/// </Summary>
Public class ExceptionHandlingUtil
{
// Default policy, which is consistent with the policy defined in the configuration file
Private const string defaultPolicy = "Default Policy ";
/// <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 );
}
}
} |