Skip to content

Instantly share code, notes, and snippets.

@alanjuden
Created January 23, 2014 05:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanjuden/8573443 to your computer and use it in GitHub Desktop.
Save alanjuden/8573443 to your computer and use it in GitHub Desktop.
using System;
using System.Text;
public static class ExceptionExtensions
{
public static string ExceptionToString(this Exception ex)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("Date/Time: " + DateTime.UtcNow.ToString());
sb.AppendLine("Exception Type: " + ex.GetType().FullName);
sb.AppendLine("Message: " + ex.Message);
sb.AppendLine("Source: " + ex.Source);
foreach (var key in ex.Data.Keys)
{
sb.AppendLine(key.ToString() + ": " + ex.Data[key].ToString());
}
if (String.IsNullOrEmpty(ex.StackTrace))
{
sb.AppendLine("Environment Stack Trace: " + ex.StackTrace);
}
else
{
sb.AppendLine("Stack Trace: " + ex.StackTrace);
}
if (ex.InnerException != null)
{
sb.AppendLine("Inner Exception: " + ex.InnerException.ExceptionToString());
}
return sb.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment