首页 文章

如何禁用.NET事件日志警告?

提问于
浏览
4

根据我们的策略,我们不再允许写入事件日志,因此我将所有事件日志代码从写入事件日志中删除,这有效,但是我不断从错误中获取随机ASP.NET 4.0警告,即使我有我的Application_Error中的代码来处理所有错误 .

有没有完全禁用事件日志记录的方法,可能是web.config更改或IIS设置禁用它?

注意到它也存在很多错误......不仅仅是我的HTTPHandler

EventLog记录的示例:

Event code: 3005 
Event message: An unhandled exception has occurred. 
Event time: 9/8/2011 10:26:04 AM 
Event time (UTC): 9/8/2011 2:26:04 PM 
Event ID: 6b56761296d24e1aa01038ce125be044 
Event sequence: 97 
Event occurrence: 1 
Event detail code: 0 

Application information: 
    Application domain: /LM/W3SVC/1/ROOT/-2-129599642336131368 
    Trust level: Full 
    Application Virtual Path: /
    Application Path: 
    Machine name: 

Process information: 
    Process ID: 6396 
    Process name: w3wp.exe 
    Account name: IIS APPPOOL\MyAppPool

Exception information: 
    Exception type: System.Exception
    Exception message: STACKTRACE

2 回答

  • 1

    ASP.NET的默认行为是将未处理的异常写入事件日志 . 阻止它将它们写入事件日志的方法是自己处理它们 . 您可以通过Application_OnError处理程序中的Global.asax文件执行此操作 .

    您还可以调用Server.ClearError()以防止它冒泡到任何其他处理程序 .

  • 4

    确实,默认行为是将所有未处理的异常记录到应用程序事件日志中,如in this answer所述 . 此行为由 web.config 中的 <system.web><healthMonitoring> 元素控制,默认设置显示为here . 我们的想法是,对于每个未处理的异常,都会引发 System.Web.Management.WebBaseErrorEvent 的实例,然后ASP.NET默认设置会将其记录到应用程序事件日志中 .

    您可以处理所有错误,也可以更改ASP.NET设置 . 可以使用 <system.web><healthMonitoring><rules> 更改导致记录这些事件的规则 . 既然你说你被禁止写入事件日志,我猜你最好的办法是删除默认规则为explained here

    <healthMonitoring>
      <rules>
        <clear />
      </rules>
    </healthMonitoring>
    

    这将删除两个默认规则,每个规则都会导致写入事件日志 .

相关问题