public static string FormatMessage(this Exception e, bool isHideStackTrace = false)
{
var sb = new StringBuilder();
var count = 0;
var appString = string.Empty;
while (e != null)
{
if (count > 0)
{
appString += " ";
}
sb.AppendLine(string.Format("{0}异常消息:{1}", appString, e.Message));
sb.AppendLine(string.Format("{0}异常类型:{1}", appString, e.GetType().FullName));
sb.AppendLine(string.Format("{0}异常方法:{1}", appString, (e.TargetSite == null ? null : e.TargetSite.Name)));
sb.AppendLine(string.Format("{0}异常源:{1}", appString, e.Source));
if (!isHideStackTrace && e.StackTrace != null)
{
sb.AppendLine(string.Format("{0}异常堆栈:{1}", appString, e.StackTrace));
}
if (e.InnerException != null)
{
sb.AppendLine(string.Format("{0}内部异常:", appString));
count++;
}
e = e.InnerException;
}
return sb.ToString();
}