Exception handling class ExceptionHandlingUtil in asp.net

Source: Internet
Author: User

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 );
        }
    }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.