namespace Kit.Helpers
{
using System;
using System.Text;
public static class ExceptionHelper_Extensions
{
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, "
");
}
}
///
/// Settings for ExceptionToStringSettings/>
///
[Flags]
public enum ExceptionToStringSettings
{
///
/// Show message
///
ShowMessageAndInnerExceptionMessages = 1,
///
/// Show assembly information
///
ShowAssemblyInformation = 2,
///
/// Show sepparators
///
ShowSeparators = 4,
//All
All = ShowMessageAndInnerExceptionMessages | ShowAssemblyInformation | ShowSeparators
}
}