【发布时间】:2014-06-12 09:56:14
【问题描述】:
我在global.asax 文件中使用以下代码:
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
Exception objErr = Server.GetLastError().GetBaseException();
string err = "Error Caught in Application_Error event<hr />" + "Current User: " + HttpContext.Current.User.Identity.Name + "<hr />" +
"Error in: " + Request.Url.ToString() +
"<hr />Error Message:" + objErr.Message.ToString() +
"<hr />Stack Trace:" + objErr.StackTrace.ToString();
//EventLog.WriteEntry("Sample_WebApp", err, EventLogEntryType.Error);
doEmail.sendEmail("Application Error - Curato (" + System.Configuration.ConfigurationManager.AppSettings["OrganisationName"].ToString() + ")", err);
// We do not want the error handled by the web.config as well, so clear the error.
Server.ClearError();
// Now redirect ourselves...
Response.Redirect("~/error.aspx?aspxerrorpath=" + Server.UrlEncode(Request.Url.PathAndQuery));
}
这会将 stackTrace 和当前用户发送到管理员电子邮件地址,并将用户重定向到友好的错误页面。
我怎样才能在err 中包含完整的跟踪信息?也就是说,与我在<%@ Page 指令中设置Trace="True" 的信息相同。
我正在探索 Trace 对象 - 并找到了如何从第 3 方阅读器 how to read trace 读取它,但我想只用本机代码阅读它。
【问题讨论】: