How To Disable .NET Event Log Warnings?
Asked Answered
M

2

6

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


Milks answered 11/1, 2012 at 18:24 Comment(8)
which errors are you receiving?Pinter
we are currently testing our password request expiration, which throws an exception if its expired... it goes to our custom error page.. but its logged a warning in the event logMilks
Possibly: technet.microsoft.com/en-us/library/cc754631%28WS.10%29.aspxCaller
one thing i did notice.. the password request is in an httphandler, would that affect it?Milks
disabling logging in IIS did not work, still produces an event log warning from ASP.NETMilks
Be certain that you understand the new policy. It may be preventing your code from writing to the event log, but are you seriously suggesting that .NET is not permitted to write to the event log? If so, see msdn.microsoft.com/en-us/library/bb398933.aspx to learn what is writing to the event log and how to configure it to write somewhere else (like to a database).Donatist
I understand our policy, our network was complaining that all our apps are spamming the eventlog so they want it out of there complete, we are now required to log to database and email only, nothing in eventlog from our apps.. but im getting warnings which are still not allowed, I'm not sure if its possible but i need to prove its not possible firstMilks
You accepted the answer below which doesn't provide much details. What exactly was the solution?Lipson
C
5

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.

Contrition answered 11/1, 2012 at 19:12 Comment(0)
L
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.

Lipson answered 10/6, 2015 at 18:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.