Asp.net mvc 如果启用自定义错误页,ELMAH不会记录异常
我有这个路径/测试/帐户,它有一个代码Asp.net mvc 如果启用自定义错误页,ELMAH不会记录异常,asp.net-mvc,elmah,Asp.net Mvc,Elmah,我有这个路径/测试/帐户,它有一个代码 throw new Exception("error"); 在my web.config中 <customErrors mode="On"> <error statusCode="404" redirect="~/404.html" /> </customErrors> 当它的模式打开时,它会显示自定义错误页面而不是异常,并且elmah不会记录它。当它关闭时,将显示异常并记录 我的理解是,我们
throw new Exception("error");
在my web.config中
<customErrors mode="On">
<error statusCode="404" redirect="~/404.html" />
</customErrors>
当它的模式打开时,它会显示自定义错误页面而不是异常,并且elmah不会记录它。当它关闭时,将显示异常并记录
我的理解是,我们需要记录异常,为此我们有elmah,但是我们不想在生产中显示这些详细的异常,所以我们有自定义的错误页面
我希望,即使在出现异常时显示自定义错误页面,我仍然希望elmah将其记录下来。自定义错误页面实际上会“吞下”异常,因此,elmah从未收到异常通知。这里有一个很好的小技巧来记录处理过的异常。创建此类:
public class ElmahExceptionLogger : IExceptionFilter
{
public void OnException (ExceptionContext context)
{
if (context.ExceptionHandled)
{
ErrorSignal.FromCurrentContext().Raise(context.Exception);
}
}
}
然后配置过滤器:
protected void Application_Start()
{
GlobalConfiguration.Configuration.Filters.Add(new ElmahExceptionLogger());
}