2012-01-11 44 views
3

根據我們的政策,我們不再允許寫入事件日誌,因此我從寫入事件日誌中刪除了所有事件日誌代碼,但是我始終從錯誤中獲取隨機ASP.NET 4.0警告,儘管我有我的Application_Error中的代碼來處理所有錯誤。如何禁用.NET事件日誌警告?

任何方式來完全禁用事件日誌記錄,也許web.config更改或IIS設置來禁用它?

注意到它了很多錯誤的太..不只是我的HttpHandler的事件日誌記錄的

例子:

 
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 


+0

您收到哪些錯誤? – 2012-01-11 18:26:21

+0

我們目前正在測試我們的密碼請求過期,如果過期它會引發異常...它會進入我們的自定義錯誤頁面..但是它在事件日誌中記錄了一條警告 – jaekie 2012-01-11 18:27:31

+0

可能:http://technet.microsoft.com /en-us/library/cc754631%28WS.10%29.aspx – Prescott 2012-01-11 18:27:40

回答

4

ASP.NET的默認行爲是編寫未處理例外事件日誌。阻止它將它們寫入事件日誌的方法是自己處理它們。您可以通過Application_OnError處理程序中的Global.asax文件完成此操作。

您也可以調用Server.ClearError()來防止它冒泡到任何其他處理程序。

1

確實,默認行爲是將所有未處理的異常記錄到應用程序事件日誌中,如in this answer所解釋的。此行爲由<system.web><healthMonitoring>元素控制,其中web.config和默認設置顯示爲here。這個想法是,對於每個未處理的異常,會引發一個System.Web.Management.WebBaseErrorEvent的實例,然後ASP.NET默認設置會將其記錄到應用程序事件日誌中。

您可以處理所有錯誤,或者您可以更改ASP.NET設置。可以使用<system.web><healthMonitoring><rules>更改導致這些事件被記錄的規則。既然你說你從編寫到事件日誌禁止我猜你最好的選擇是隻刪除默認規則explained here

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

從而消除了兩個默認規則,各從而導致寫入事件日誌。