ToStringReccurent
Sometimes it is required to collect exception information in textual format. This method serializes general info about exception and all included exceptions reccursively. I'm using this for sending email error reports.
Source
public static string ToStringReccurent(this Exception exception)
{
if (exception == null)
{
return "empty";
}
return string.Format
("Exception: {0}\nMessage: {1}\nStack Trace: {2}\nInner {3}", exception.GetType(),
exception.Message, exception.StackTrace, exception.InnerException.ToStringReccurent());
}
Example
private void appDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
e.Handled = true;
MessageBox.Show("Application encountered an error, sorry for inconvinience.", "Error", MessageBoxButton.OK, MessageBoxImage.Hand);
Process.Start(string.Format("mailto:{0}?subject={1}&body={2}", DeveloperEMail,
"StatusFlags Exception", e.Exception.ToStringReccurent().UrlEncode()));
Shutdown();
}