Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically Logging Errors With Elmah : Logging specific information

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);
}
like image 663
tugberk Avatar asked Jul 02 '11 11:07

tugberk


1 Answers

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);

}
like image 53
Geo Avatar answered Nov 02 '22 08:11

Geo