VEU.WathBody/3-app/1-lib/Kit.Helpers/Extension/SystemExceptionExtensionMet...

33 lines
1.0 KiB
C#

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, "<br />");
}
}
}