/// <summary> /// This operation recursively calls itself if the specified /// exception has inner exceptions. /// </summary> /// /// <param name="exception"></param> /// <param name="outerException"></param> /// /// <returns></returns> /// public static CapturedExceptionCollection<CapturedException> CaptureException(Exception exception, Exception outerException) { if (exception == null) { throw new ArgumentNullException("exception"); } CapturedExceptionCollection<CapturedException> result = new CapturedExceptionCollection<CapturedException>(); CapturedException item = new CapturedException(exception); result.Add(item); if (outerException == null) { item.OuterException = true; } System.Exception inner = exception.InnerException; if (inner != null) { result.Merge(CaptureException(inner, exception).GetEntities()); } return result; }
/// <remarks /> /// private static string FormatExceptionAsXml(CapturedException exception) { return new StringBuilder() .Append("<header>").Append(exception.ExceptionType).Append("</header>") .Append("<type>").Append(exception.ExceptionType).Append("</type>") .Append("<message>").Append(exception.ExceptionMessage).Append("</message>") .Append("<source>").Append(exception.ExceptionSource).Append("</source>") .Append("<stacktrace>").Append(exception.StackTrace).Append("</stacktrace>").ToString(); }
/// <remarks /> /// private static string FormatException(CapturedException exception) { return new StringBuilder() .Append("Type: ").Append(exception.ExceptionType).AppendLine() .Append("Message: ").Append(exception.ExceptionMessage).AppendLine() .Append("Source: ").Append(exception.ExceptionSource).AppendLine() .Append("StackTrace: ").Append(exception.StackTrace).AppendLine() .AppendLine().AppendLine().ToString(); }