When to log exception?

Posted by Rune on Stack Overflow See other posts from Stack Overflow or by Rune
Published on 2010-04-04T14:08:47Z Indexed on 2010/04/04 14:13 UTC
Read the original article Hit count: 486

try
{
   // Code
}
catch (Exception ex)
{
   Logger.Log("Message", ex);
   throw;
}

In the case of a library, should I even log the exception? Should I just throw it and allow the application to log it? My concern is that if I log the exception in the library, there will be many duplicates (because the library layer will log it, the application layer will log it, and anything in between), but if I don't log it in the library, it'll be hard to track down bugs. Is there a best practices for this?

© Stack Overflow or respective owner

Related posts about logging

Related posts about best-practices