2013-05-27 4 views
1

ASP.NET MVC 4 응용 프로그램에서 ELMAH를 구성했습니다. Application_Error 이벤트에 몇 가지 코드를 작성하여 오류의 상태 코드를 확인하고 오류 컨트롤러를 호출하여 404, 500 오류에 대한 적절한보기를 반환합니다.구성에서 ELMAH 사용 안 함

Elmah는 Application_Error에 도달하면 오류를 기록합니다. ELMAH를 자동으로 허용하는 대신 Application_Error에서 수동으로 트리거하려고합니다. 그래서, 오류를 자동으로 기록하는 elmah를 비활성화하기 위해 web.config에서 설정할 수있는 구성 등록 정보가 있습니까?

답변

0

당신은 같은 것을 할 수 있습니다

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(); 
     } 

의 Web.config :

<appSettings> 
    <add key="LoggingEnabled" value="1"/> 
    </appSettings>