I log exceptions with Elmah and was wondering if the technique I am using is good design?
Right now I catch and re throw exceptions that occur in various classes and methods, and log them to Elmah in the main try-catch block of the program.
// Main Program
try { // Some code that fires off other classes, etc... MyTestClass myTestClass = new MyTestClass(); myTestClass.Execute(); } catch(Exception ex) { ErrorSignal.FromCurrentContext().Raise(ex); } // MyTestClass
public class MyTestClass { public object ApiResult { get; set; } public string Execute() { try { // execute some code // .... // set xml message ApiResult = "User information xml response"; } catch (Exception ex) { // set xml message ApiResult = "something went wrong xml error response..."; throw; } } } Would it be better to log the exceptions where they occur? Another question, should I log errors that I can handle without catching exceptions? For example if something is null, should I do a test for that (if null...) and log a message in Elmah?