我在try-catch块中记录了Elmah的错误。这是代码;
try {
DateTime.Parse("poo");
} catch (Exception err) {
Elmah.ErrorSignal.FromCurrentContext().Raise(err);
}
我想记录一些特定的信息,例如可以从相同上下文中的先前方法或属性中检索到的某些信息,但是Exception属性是只读的。最好的方法是什么?
我的主要目标是能够执行以下操作;
} catch (Exception err) {
err.Message += "poo";
Elmah.ErrorSignal.FromCurrentContext().Raise(err);
}
最佳答案
您可以创建自己的异常对象,并将其传递给Elmah。
设置静态助手方法并执行类似的操作
public static void HandleError(Exception ex, String customMsg)
{
Exception newEx = new Exception(customMsg, ex);
Elmah.ErrorSignal.FromCurrentContext().Raise(newEx);
}
关于.net - 使用Elmah编程地记录错误:记录特定信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6556684/