public static string GetFormattedException(Exception ex, bool isRecursive)
{
StringBuilder exceptionString = new StringBuilder();
if (isRecursive)
exceptionString.AppendFormat(""************ Inner Exception
************{0}"", Environment.NewLine);
else
exceptionString.AppendFormat(""*************** Exception
***************{0}"", Environment.NewLine);
exceptionString.AppendFormat(""Exception Message:{0}{1}{2}"",
Environment.NewLine, ex.Message, Environment.NewLine);
exceptionString.AppendFormat(""Stack Trace:{0}{1}{2}"",
Environment.NewLine, ex.StackTrace, Environment.NewLine);
exceptionString.AppendFormat(""Source:{0}{1}{2}"",
Environment.NewLine, ex.Source, Environment.NewLine);
//recurse into inner exceptions
if (ex.InnerException != null)
{
exceptionString.Append(String.Format(""{0}{1}"",
GetFormattedException(ex.InnerException, true), Environment.NewLine));
}
return exceptionString.ToString();
}