StringBuilder sb = new StringBuilder();
sb.AppendLine("\r\n****************************异常文本****************************");
sb.AppendLine("\r\n【出现时间】:" + DateTime.Now.ToString());
if (ex != null)
{
ex = BuildErrorMessage(ex);
sb.Append("\r\n【异常类型】:" + ex.ToString());
sb.Append("\r\n【异常信息】:" + ex.Message);
sb.Append("\r\n【错误源】:" + ex.Source);
sb.Append("\r\n【堆栈信息】:" + ex.StackTrace);
}
LogHelpr.Log(":" + sb, "错误日志位置");
private static Exception BuildErrorMessage(Exception ex)
{
while (ex.InnerException != null)
{
ex = ex.InnerException;
}
return ex;
}