开发者

Programmatically Logging Errors With Elmah : Logging specific information

I am logging error wit开发者_如何学运维h 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);
}


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

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜