I’m developing a web application which takes advantage of Microsoft Enterprise Library’s Logging block to log Errors in a custom sink I’ve developed. Now in order to log unhandled exceptions I’ve hooked on the Application_Error event of the HttpApplication object, the code looks something like that:
void application_Error(object sender, EventArgs e)
HttpApplication app = (HttpApplication)sender;
Exception error = app.Server.GetLastError();
if (error != null)
LogEntry errorEntry = new LogEntry();
errorEntry.Title = error.Message;
errorEntry.EventId = (int)(LoggingErrorCodes.Unhandled_Error);
errorEntry.Severity = System.Diagnostics.TraceEventType.Error;
So far so good, when I run the application though, I was getting an exception for almost every request made, which resulted of course in a log entry beeing written on the log. The exception had the intuitive message “File does not exist.” , the exception type was HttpException and the call stack indicated that the exception was originating from the ProcessRequestInternal method of HttpStaticHandler class. Finally the page was loading up fine (no obvious errors).
Ok here is the trivia question (don’t read bellow before answering that ;-)) can you imagine why this was happening?
After spending a couple of hours on that and doing a little disassembling on the HttpStaticHandler class (sorry MS had no other way) I’ve discovered that a file was actually missing and that’s why I was getting the exception,
But which file? Once more the page I was requesting was loading up fine. Can you, after these clues, imagine what was going on?