54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
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, "<br />");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Settings for ExceptionToStringSettings/>
|
|
/// </summary>
|
|
[Flags]
|
|
public enum ExceptionToStringSettings
|
|
{
|
|
/// <summary>
|
|
/// Show message
|
|
/// </summary>
|
|
ShowMessageAndInnerExceptionMessages = 1,
|
|
|
|
/// <summary>
|
|
/// Show assembly information
|
|
/// </summary>
|
|
ShowAssemblyInformation = 2,
|
|
|
|
/// <summary>
|
|
/// Show sepparators
|
|
/// </summary>
|
|
ShowSeparators = 4,
|
|
|
|
//All
|
|
All = ShowMessageAndInnerExceptionMessages | ShowAssemblyInformation | ShowSeparators
|
|
}
|
|
} |