zoukankan      html  css  js  c++  java
  • 公用类库(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);  
            }
        }
    }
  • 相关阅读:
    iOS8及以后 地图定位当前城市
    UITextView换行问题解决办法
    使用七牛上传图片代码,导入文件常遇问题解决方法
    CocoaPods安装和使用
    Xcode7真机测试
    Label 添加表情图片
    TTTAttributedLabel使用介绍(转)
    带有中文的url和NSString中文的转换
    正则表达式的使用 选取有用数据
    导航网格配置笔记
  • 原文地址:https://www.cnblogs.com/mcgrady/p/2970109.html
Copyright © 2011-2022 走看看