通过呼叫记录到抬起ELMAH增加消息到差错(e)
-
26-09-2019 - |
题
我一点在如何将信息添加到一个错误混淆编程与ELMAH记录。
例如:
public ActionResult DoSomething(int id)
{
try { ... }
catch (Exception e)
{
// I want to include the 'id' param value here, and maybe some
// other stuff, but how?
ErrorSignal.FromCurrentContext().Raise(e);
}
}
似乎所有ELMAH能做的就是登录原例外,我怎么也登录我自己的调试信息?
解决方案
可以抛出一个新的异常设置原来那样的内部异常和ELMAH将记录消息二者:
catch(Exception e)
{
Exception ex = new Exception("ID = 1", e);
ErrorSignal.FromCurrentContext().Raise(ex);
}
将显示
System.Exception: ID = 1 ---> System.NullReferenceException: Object reference not set to an instance of an object.
其他提示
我发现我也可以这样做:
Elmah.ErrorSignal.FromCurrentContext().Raise(new NotImplementedException("class FbCallback.Page_Load() Request.Url= " + Request.Url));
要记录我自己的消息。然后,在当我浏览到
http://localhost:5050/elmah.axd
我看到我的消息类型NotImplementedException。 不是很漂亮,但作品。
不隶属于 StackOverflow