对于我正在工作的一个项目,我们正在实现的一件事是我们在我的团队的一些较早的ASP.NET和MVC项目中为其编写的代码-一个Application_Error
异常捕获器,它向开发团队发送一封邮箱,其中包含异常经验和最相关的详细信息.
下面是它的外观:
Global.asax:
protected void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError();
string path = "N/A";
if (sender is HttpApplication)
path = ((HttpApplication) sender).Request.Url.PathAndQuery;
string args = string.Format("<b>Path:</b> {0}", path);
// Custom code that generates an HTML-formatted exception dump
string message = Email.GenerateExceptionMessage(ex, args);
// Custom code that sends an email to the dev team.
Email.SendUnexpectedErrorMessage("Some App", message);
}
不过有一个"小"问题——当我故意让代码的一部分抛出异常以测试这种机制时...
public static void GetMuffinsByTopping(string topping)
{
throw new Exception("Test Exception!", new Exception("Test Inner Exception!!!"));
// Actual repository code is unreachable while this test code is there
}
前端JavaScript立即拦截HTTP 500请求,但是没有达到上面提到的global.asax.cs代码(我在该方法的第一个执行行上设置了断点).
Question:如何让"旧"Application_Error
处理程序发送错误邮箱,以便我们团队的开发人员能够更轻松地调试我们的应用程序?