What to log when an exception occurs?

Posted by Rune on Stack Overflow See other posts from Stack Overflow or by Rune
Published on 2010-04-04T14:29:36Z Indexed on 2010/04/04 14:33 UTC
Read the original article Hit count: 209

public void EatDinner(string appetizer, string mainCourse, string dessert)
{
   try
   {
      // Code
   }
   catch (Exception ex)
   {
      Logger.Log("Error in EatDinner", ex);
      return;
   }
}

When an exception occurs in a specific method, what should I be logging?

I see a lot of the above in the code I work with. In these cases, I always have to talk to the person who experienced the error to find out what they were doing, step through the code, and try to reproduce the error.

Is there any best practices or ways I can minimize all this extra work? Should I log the parameters in each method like this?

Logger.Log("Params: " + appetizer + "," + mainCourse + "," + dessert, ex);

Is there a better way to log the current environment? If I do it this way, will I need to write out all this stuff for each method I have in my application? Are there any best practices concerning scenarios like this?

© Stack Overflow or respective owner

Related posts about logging

Related posts about exception