Asp.net mvc 4 在配置中禁用ELMAH

Asp.net mvc 4 在配置中禁用ELMAH,asp.net-mvc-4,elmah,Asp.net Mvc 4,Elmah,我已经在ASP.NET MVC 4应用程序中配置了ELMAH。我在Application\u Error事件中编写了一些代码来检查错误的状态代码,并调用错误控制器来返回404500个错误的适当视图 如果出现应用程序错误,Elmah会记录错误。我不想让ELMAH自动执行该操作,而是从应用程序\u错误中手动触发它。那么,我是否可以在web.config中设置任何配置属性来禁用elmah自动记录错误。您可以执行以下操作: Global.asax.cs: protected void ErrorLog

我已经在ASP.NET MVC 4应用程序中配置了ELMAH。我在
Application\u Error
事件中编写了一些代码来检查错误的状态代码,并调用错误控制器来返回404500个错误的适当视图


如果出现
应用程序错误
,Elmah会记录错误。我不想让ELMAH自动执行该操作,而是从
应用程序\u错误中手动触发它。那么,我是否可以在web.config中设置任何配置属性来禁用elmah自动记录错误。

您可以执行以下操作:

Global.asax.cs:

 protected void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
        {
            if (ConfigurationManager.AppSettings["LoggingEnabled"] == "0")
            {
                e.Dismiss();
                return;
            }

            var httpContext = e.Context as HttpContext;
            if (httpContext == null)
            {
                return;
            }

            var error = new Error(e.Exception, httpContext);
            ErrorLog.GetDefault(httpContext).Log(error);
            e.Dismiss(); 
        }
 <appSettings>
    <add key="LoggingEnabled" value="1"/>
  </appSettings>
web.config:

 protected void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
        {
            if (ConfigurationManager.AppSettings["LoggingEnabled"] == "0")
            {
                e.Dismiss();
                return;
            }

            var httpContext = e.Context as HttpContext;
            if (httpContext == null)
            {
                return;
            }

            var error = new Error(e.Exception, httpContext);
            ErrorLog.GetDefault(httpContext).Log(error);
            e.Dismiss(); 
        }
 <appSettings>
    <add key="LoggingEnabled" value="1"/>
  </appSettings>