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

发布于 2024-12-26 05:52:40 字数 912 浏览 1 评论 0原文

根据我们的政策,我们不再允许写入事件日志,因此我删除了所有事件日志代码,使其不再写入事件日志,这有效,但是我不断从错误中收到随机的 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


Per our policy we are no longer allowed to write to event log, so I removed all my event log code from writing to the event log, which works, however I keep getting random ASP.NET 4.0 Warnings from the errors, even though I have code in my Application_Error to handle all errors.

Any way to disable event logging completely, maybe a web.config change or IIS setting to disable it?

Noticing it for a lot of errors too.. not just my HTTPHandler

Example of the EventLog record:

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


如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

往事随风而去 2025-01-02 05:52:40

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

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

The default behavior of ASP.NET is to write unhandled exceptions to the event log. The way to prevent it from writing them to the event log is to handle them yourself. You can do this via your Global.asax file in the Application_OnError handler.

You can also call Server.ClearError() to prevent it from bubbling up to any other handlers.

半夏半凉 2025-01-02 05:52:40

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

您可以处理所有错误,也可以更改 ASP.NET 设置。可以使用 更改导致记录这些事件的规则。既然你说你被禁止写入事件日志,我猜你最好的选择就是删除默认规则,如此处解释< /a>:

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

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

It's true that the default behavior is to log all unhandled exceptions to Application event log as explained in this answer. This behavior is controlled by <system.web><healthMonitoring> element in web.config and default settings are shown here. The idea is that for every unhandled exception an instance of System.Web.Management.WebBaseErrorEvent is raised and then ASP.NET default settings cause it to be logged into Application event log.

You could handle all errors or you could change ASP.NET settings. Rules which cause these events to be logged can be changed using <system.web><healthMonitoring><rules>. Since you say you're prohibited from writing into the event log I would guess your best bet is to just erase the default rules as explained here:

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

which removes the two default rules each causing writes to event log.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文