/// <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; }
public void TestCapturedExceptionCollection() { CapturedExceptionCollection<CapturedException> exceptions = new CapturedExceptionCollection<CapturedException>(); exceptions.Add(new CapturedException(new ServiceException("Failed to invoke service"))); Assert.IsNotEmpty(exceptions.GetEntities()); Assert.IsNotNull(exceptions.AppDomainName); Assert.IsNotNull(exceptions.AssemblyFullName); Assert.IsNotNull(exceptions.MachineName); Assert.IsNotNull(exceptions.ThreadIdentity); Assert.IsNotNull(exceptions.TimeStamp); Assert.IsNotNull(exceptions.WindowsIdentity); foreach (CapturedException exception in exceptions) { Assert.IsNotNull(exception); Console.WriteLine(exception); } }
/// <remarks /> /// private static string FormatExceptionHeaderAsXml(CapturedExceptionCollection<CapturedException> exceptions) { return new StringBuilder() .AppendFormat("<ExceptionSummary machine=\"{0}\" identity=\"{1}\" assembly=\"{2}\" appdomain=\"{3}\" timestamp=\"{4}\" >", exceptions.MachineName, exceptions.WindowsIdentity, exceptions.AssemblyFullName, exceptions.AppDomainName, exceptions.TimeStamp).ToString(); }
/// <remarks /> /// private static string FormatExceptionHeader(CapturedExceptionCollection<CapturedException> exceptions) { return new StringBuilder() .Append("Time: ").Append(exceptions.TimeStamp).AppendLine() .Append("Machine: ").Append(exceptions.MachineName).AppendLine() .Append("Windows Identity: ").Append(exceptions.WindowsIdentity).AppendLine() .Append("Assembly: ").Append(exceptions.AssemblyFullName).AppendLine() .Append("App Domain: ").Append(exceptions.AppDomainName).AppendLine() .AppendLine(new String('-', 80)).AppendLine().ToString(); }