0

By default ASP.NET writes any unhandled exception to the default ASP.NET X.Y.Z.0 event log source. Is it possible to specify either configuration that the events and exceptions for a particular application has to be logged in a specific event log Source?

The reason is that I would want all issues directly related to my application to be stored in a separate event log category that can then be filtered against.

Knaģis
  • 20,827
  • 7
  • 66
  • 80

1 Answers1

0

I've never done this before, but could you use the Global.Application_Error() method and use syntax like this within it:

   Exception ex = Server.GetLastError().GetBaseException();

   //log to Event Log
   EventLog.WriteEntry("Whatever",
     "MESSAGE: " + ex.Message + 
     "\nSOURCE: " + ex.Source +
     "\nFORM: " + Request.Form.ToString() + 
     "\nQUERYSTRING: " + Request.QueryString.ToString() +
     "\nTARGETSITE: " + ex.TargetSite +
     "\nSTACKTRACE: " + ex.StackTrace, 
     EventLogEntryType.Error);
ED-209
  • 4,706
  • 2
  • 21
  • 26
  • this is how I can create my own event source to log events from code. The problem I have is that I need to log exceptions that ASP.NET logs itself (for example, errors like `web.config cannot be parsed`). – Knaģis Oct 24 '13 at 09:35
  • @Knaģis ah ok. I have changed my answer now in the hope that it might help, but I've never done this before so I'm kind of guessing :) – ED-209 Oct 24 '13 at 09:53
  • the new sample does not work for the case when the error occurs when initializing the application (like the mentioned config parsing) and potentially other low levels errors. – Knaģis Oct 24 '13 at 10:29
  • @Knaģis OK, I give up. Does it work ok for other unhandled exceptions? – ED-209 Oct 24 '13 at 10:36
  • @Knaģis what you're trying to achieve sounds to me like something you'd need to configure in IIS. – ED-209 Oct 24 '13 at 10:44