using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Kit.Core.Kit.Helpers.Extension { public static class SystemExceptionExtensionMethods { public static string GetInfoAsPlainText(this Exception ex) { if (ex == null) return string.Empty; StringBuilder sb = new StringBuilder(); sb.AppendFormat("Source: {0}", ex.Source); sb.AppendLine(); sb.AppendFormat("Message: {0}", ex.Message); sb.AppendLine(); sb.AppendFormat("StackTrace: {0}", ex.StackTrace); sb.AppendLine(); if (ex.InnerException != null) { sb.AppendLine("InnerException:"); sb.Append(ex.InnerException.GetInfoAsPlainText()); } return sb.ToString(); } public static string GetInfoAsHtml(this Exception ex) { return ex.GetInfoAsPlainText().Replace(Environment.NewLine, "
"); } } }