views:

207

answers:

3

Stack trace is not enabled when a .net assembly is deployed in release mode. So we cannot get the stack trace from an exception and log it in production environment.

For knowing where an exception occurred in the production code and log it, we use a weird approach which I am not comfortable with but I cannot come up with a better solution which logs the exact method where the exception occurred in the first place.

Please note that the logging mechanism is also used for determining bugs. So when an NullReferenceException or IndexOutOfBoundsException is raised, it is not helpful to get the exception type and message only, we often need to know where exactly the exception occurred.

How do you deal with this? What information do you log on your production code when an exception occurs and how do you determine what the problem is by that information?

+2  A: 

Check out ELMAH, I haven't implemented it myself but it seems to be getting some attention.

http://www.hanselman.com/blog/ELMAHErrorLoggingModulesAndHandlersForASPNETAndMVCToo.aspx

Once ELMAH has been dropped into a running web application and configured appropriately, you get the following facilites 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.
  • A number of backing storage implementations for the log, including in-memory, Microsoft SQL Server and several contributed by the community.
Jon Erickson
+1  A: 

We have no problems logging stack traces for release code, however we do always ship the .pdb files with our releases. Without the pdb you will always be limited to the symbol information contained within the assembly itself, which for assemblies in release mode wont be much.

Kragen
A: 

All of our release code has stack traces. The only thing we're missing is the line numbers, as those come from the .pdb. Are you running an obfuscator?

Adam Ruth