views:

68

answers:

2

I have an asp.net MVC app in production that very seldom but very consistently is throwing the same exception and I don't know why. I cannot, no matter what I do, reproduce the exception in neither the production nor development environments.

I am logging all unhandled exceptions. I have the date/time, controller, action, exception message, and call stack of each logged exception. So, I have a good idea where this is happening. Just not why.

To solve, I am considering wrapping this code in a try/catch and manually logging the names/values of all relevant variables. I would deploy this new logging capability and once solved, I would remove it.

But, then I was thinking how I bet there is a better, more portable way of doing this. Can anyone help?

EDIT

This is what I am currently working off of.

+2  A: 

Have you considered using ELMAH?

ELMAH (Error Logging Modules and Handlers) is an application-wide error logging facility that is completely pluggable. It can be dynamically added to a running ASP.NET web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment.

Once ELMAH has been dropped into a running web application and configured appropriately, you get the following facilities without changing a single line of your code:

  • Logging of nearly all unhandled exceptions.
  • A web page to remotely view the entire log of recoded exceptions.
  • A web page to remotely view the full details of any one logged exception.
  • In many cases, you can review the original yellow screen of death that ASP.NET generated for a given exception, even with customErrors mode turned off.
  • An e-mail notification of each error at the time it occurs.
  • An RSS feed of the last 15 errors from the log.

ELMAH won't log the state of the application, but perhaps you could throw a custom exception that would encapsulate any state you need to see. Are you looking to log something like a core dump? Perhaps something like debugdiag would be better:

The Debug Diagnostic Tool (DebugDiag) is designed to assist in troubleshooting issues such as hangs, slow performance, memory leaks or fragmentation, and crashes in any user-mode process. The tool includes additional debugging scripts focused on Internet Information Services (IIS) applications, web data access components, COM+ and related Microsoft technologies.

Andrew Hare
Will ELMAH log state?
Ronnie Overby
A: 

Are you catching a database exception somewhere and somehow your model variable doesn't get filled, or your code doesn't branch off to indicate the need to try again (i.e. error page/message)?

I also would recommend ELMAH, it gives you a lot of the HTTP/REQUEST/RESPONSE type headers from the request and it may have enough information for you to debug the issue better/faster. You'll probably have to do some work to get Elmah working because you already have a catch-all handler/logging mechanism, so there are not really any uncaught exceptions that ELMAH could handle just out of the box.

Redbeard 0x0A