• 公用类库(3) 异常处理类ExceptionHandlingUtil


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

    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>

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

    namespace Tmac.Utilities
    {
        /// <summary>
        /// 异常处理操作类
        /// </summary>
        public class ExceptionHandlingUtil
        {
            //默认策略,与配置文件中定义的一致
            private const string defaultPolicy = "Default Policy";
    
            /// <summary>
            /// 记录异常日志
            /// </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);  
            }
        }
    }
  • 相关阅读:
    warmup_csaw_2016
    pwn-简单栈溢出
    吃土
    编程中的进制转换
    linux系统安全及应用——账号安全(基本安全措施)
    vmware vSphere虚拟网络之标准交换机(二)
    vmware vSphere虚拟网络(一)
    服务器虚拟化技术概述
    用shell脚本安装apache
    The server of Apache (二)——apache服务客户端验证
  • 原文地址:https://www.cnblogs.com/mcgrady/p/2970109.html
Copyright © 2020-2023  润新知