asp.net中异常处理类ExceptionHandlingUtil

作者:袖梨 2022-06-25

首先创建配置文件,代码如下:

 代码如下 复制代码


       
           
               
                                            postHandlingAction="NotifyRethrow">
                       
                                                            logCategory="Exception" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
                                formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
                                priority="0" />
                       

                   

               

           

       

   

两个公开方法,全部代码如下:

 代码如下 复制代码

namespace Tmac.Utilities
{
    ///


    /// 异常处理操作类
    ///

    public class ExceptionHandlingUtil
    {
        //默认策略,与配置文件中定义的一致
        private const string defaultPolicy = "Default Policy";

        ///


        /// 记录异常日志
        ///

        ///
        ///
        public static bool HandleException(Exception ex)
        {
            return HandleException(ex,defaultPolicy);
        }

        public static bool HandleException(Exception ex, string policy)
        {
            return ExceptionPolicy.HandleException(ex, policy); 
        }
    }
}

相关文章

精彩推荐