using System; using System.Text; namespace Sony.Filtr.Utility.Extensions { [Flags] public enum ExceptionData { Message = 1, StackTrace = 2, All = Message | StackTrace } public static class ExceptionExtensions { public static string GetFullMessage(this Exception ex, ExceptionData dataToShow = ExceptionData.All) { StringBuilder builder = new StringBuilder(); Exception current = ex; while (current != null) { if ((dataToShow & ExceptionData.Message) == ExceptionData.Message) { builder.AppendLine(current.Message); } if ((dataToShow & ExceptionData.StackTrace) == ExceptionData.StackTrace) { builder.AppendLine(current.StackTrace); } current = current.InnerException; } return builder.ToString(); } public static string GetFullMessage(this AggregateException ex, ExceptionData dataToShow = ExceptionData.All) { StringBuilder builder = new StringBuilder(); foreach (var e in ex.InnerExceptions) { builder.AppendLine(e.GetFullMessage()); } return builder.ToString(); } } }