Should I catch exceptions only to log them?
c#, exception, logging
Solution
Definitely not. You should find the correct place to handle the exception (actually do something, like catch-and-not-rethrow), and then log it. You can and should include the entire stack trace of course, but following your suggestion would litter the code with try-catch blocks.
Problem
Should I catch exceptions for logging purposes? ``` public foo(..) { try { ... } catch (Exception ex) { Logger.Error(ex); throw; } } ``` If I have this in place in each of my layers (DataAccess, Business and WebService) it means the exception is logged several times. Does it make sense to do so if my layers are in separate projects and only the public interfaces have try/catch in them? Why? Why not? Is there a different approach I could use?