示例#1
0
        public static void ExceptionReport(Exception exception)
        {
            if (exception == null)
            {
                return;
            }

            while (true)
            {
                switch (exception)
                {
                case TargetInvocationException targetInvocationException when targetInvocationException.InnerException != null:
                    exception = targetInvocationException.InnerException;
                    continue;

                case AggregateException aggregateException when aggregateException.InnerException != null:
                    exception = aggregateException.InnerException;
                    continue;

                default:
                    break;
                }

                break;
            }

            if (exception is AssertionFailedException)
            {
                Console.WriteLine(exception.Message);
                Console.WriteLine(StringEx.Implode("\r\n", exception.StackTrace.Split(CharHelper.GetNewLineChars()).Skip(1)));
                return;
            }

            var report = new StringBuilder();

            report.Append("Exception");
            report.Append("\r\n\r\n");
            var current = exception;

            for (; current != null; current = current.InnerException)
            {
                report.Append(StringEx.Join("\r\n\r\n", "== Exception Type ==", current.GetType().Name, "== Exception Message ==", current.Message, "== Source ==", current.Source, "== Stacktrace ==", current.StackTrace));
                report.Append("\r\n\r\n");
            }

            Console.WriteLine(report);
        }