问题
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
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/8824581/how-to-disable-net-event-log-warnings