コード例 #1
0
ファイル: ExceptionHelper.cs プロジェクト: xiaowu351/ZPW.Util
            /// <summary>
            /// 解析异常类型
            /// </summary>
            /// <param name="innerExp">Exception对象</param>
            /// <returns>返回详细信息</returns>
            private static string HandleException(Exception innerExp)
            {
                StringBuilder builder = new StringBuilder();

                while (innerExp != null)
                {
                    //服务端异常
                    FaultException <string> faultEx = innerExp as FaultException <string>;
                    if (faultEx != null)
                    {
                        builder.AppendFormat("-------------------{0}:{1}-----------------\r\n", faultEx.GetType().Name, faultEx.Message);
                        builder.AppendLine(faultEx.Detail);
                        break;
                    }

                    //SOAP 错误
                    FaultException faultEx1 = innerExp as FaultException;
                    if (faultEx1 != null)
                    {
                        builder.AppendLine(faultEx1.ToString());
                        break;
                    }

                    //给进程或操作分配的时间过期时引发的异常
                    TimeoutException timeoutEx = innerExp as TimeoutException;
                    if (timeoutEx != null)
                    {
                        builder.AppendLine("连接服务器发生异常,超时!");
                        builder.AppendLine(timeoutEx.ToString());
                        break;
                    }

                    //服务或客户端应用程序中的通信错误。
                    CommunicationException commuEx = innerExp as CommunicationException;
                    if (commuEx != null)
                    {
                        builder.AppendLine("连接服务器发生异常,通信错误!");
                        builder.AppendLine(commuEx.ToString());
                        break;
                    }

                    builder.AppendFormat("-----------------{0} : {1}--------------------\r\n{2}", innerExp.GetType().Name,
                                         innerExp.Message, innerExp.StackTrace);
                    innerExp = innerExp.InnerException;
                }
                return(builder.ToString());
            }
コード例 #2
0
        private void MakeLogs()
        {
            var logger = this._loggerFactory.CreateLogger("MakeLogs");

            var       index = this.Dice.Next(1, 100);
            Exception ex0;

            switch (index)
            {
            case int n when(n < 10):
                ex0 = new Models.RequiredConfigurationMissingException("ConfigKeyA", "Application will not run correctly!");

                logger.LogCritical(ex0, "{0}", ex0.ToString());
                break;

            case int n when(n >= 10 && n < 20):
                ex0 = new Models.RequiredConfigurationBadValueException("ConfigKeyA", -20, "Application will not run correctly until this key has a valid value supplied (expected (int) 1-1000)");

                logger.LogCritical(ex0, "{0}", ex0.ToString());
                break;

            case int n when(n >= 20 && n < 40):
                ex0 = new InvalidOperationException("The code did a bad thing, this is why... Process will not crash, but a unit of work may have been lost");

                logger.LogError(ex0, "{0}", ex0.ToString());
                break;

            case int n when(n >= 40 && n < 50):
                ex0 = new TimeoutException("It took a couple of tries, but it worked eventually");

                logger.LogWarning(ex0, "{0}", ex0.ToString());
                break;

            case int n when(n >= 50 && n < 70):
                logger.LogInformation("This is information for **Business** Users, do not mis-use this for developer messages...");

                break;

            case int n when(n >= 70 && n < 80):
                logger.LogDebug("Debug (coarse debugging) for Developers");

                break;

            default: logger.LogTrace("Trace (very detailed debugging) For Developers"); break;
            }
        }
コード例 #3
0
 /// <summary>
 /// The behaviour to perform when a timeout exception occurs during a Close.
 /// </summary>
 /// <param name="exception">The exception.</param>
 public void PerformCloseTimeoutExceptionBehaviour(TimeoutException exception)
 {
     Console.Error.WriteLine(exception == null ? NullPhrase : exception.ToString());
 }
コード例 #4
0
 public void captures_exception_data()
 {
     theErrorReport.ExceptionText.ShouldBe(theException.ToString());
     theErrorReport.ExceptionMessage.ShouldBe(theException.Message);
     theErrorReport.ExceptionType.ShouldBe(theException.GetType().FullName);
 }
コード例 #5
0
 /// <summary>
 /// The behaviour to perform when a timeout exception occurs while the service operation is called.
 /// </summary>
 /// <param name="exception">The exception.</param>
 public void PerformTimeoutExceptionBehaviour(TimeoutException exception)
 {
     Console.Out.WriteLine(exception == null ? NullPhrase : Prefix + "Timeout: " + exception.ToString());
 }