日志

public BDMSSystemException(string message, Exception innerException) {
if (!string.IsNullOrEmpty(message)) {
string path = string.Empty;
if (null != HttpContext.Current) {
path = HttpContext.Current.Server.MapPath("~/SystemError/log.txt");
} else {
path = string.Concat(AppDomain.CurrentDomain.BaseDirectory, "\\", "SystemError\\log.txt");
}
string contents = string.Format("{0}{1}ExceptionType:{2}{0}{1}Message:{3}{0}{1}", new object[] { Environment.NewLine, new string('-', 5), base.GetType().Name, message });
int num = 1;
while (innerException != null) {
contents = contents + string.Format("{0}{1}InnerExceptionType:{2}{0}{1}Message:{3}{0}{1}StackTrace:{4}{0}{1}TargetSite:{5}{0}{1}", new object[] { Environment.NewLine, new string('-', 10 * num), innerException.GetType().Name, innerException.Message, innerException.StackTrace, innerException.TargetSite });
num++;
innerException = innerException.InnerException;
}
File.AppendAllText(path, contents, Encoding.UTF8);
}
}

posted on 2014-09-05 09:07  Struggling Rookie  阅读(103)  评论(0编辑  收藏  举报