Reputation: 58434
I am logging error with Elmah inside a try-catch block. here is the code;
try {
DateTime.Parse("poo");
} catch (Exception err) {
Elmah.ErrorSignal.FromCurrentContext().Raise(err);
}
I would like to log some specific info like some information which can be retrieved from previous methods or properties on the same context but the Exception properties are readonly. what is the best way to do that?
My main goal is to be able to do something like below;
} catch (Exception err) {
err.Message += "poo";
Elmah.ErrorSignal.FromCurrentContext().Raise(err);
}
Upvotes: 17
Views: 5510
Reputation: 286
You could create your own exception object and pass that to Elmah.
Setup a static helper method and do something like
public static void HandleError(Exception ex, String customMsg)
{
Exception newEx = new Exception(customMsg, ex);
Elmah.ErrorSignal.FromCurrentContext().Raise(newEx);
}
Upvotes: 26