ELMAH添加消息通过调用错误记录到提高(五)错误、消息、ELMAH

由网友(霸气伤感的大全)分享简介:我有点困惑如何将信息添加到错误记录的编程与ELMAH。I'm a bit confused at how to add a message to an error logged programatically with ELMAH.例如:public ActionResult DoSomething(int id...

我有点困惑如何将信息添加到错误记录的编程与ELMAH。

I'm a bit confused at how to add a message to an error logged programatically with 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可以做的是记录生异常,我该怎么也登录自己的调试信息?

It seems all Elmah can do is log the raw exception, how can I also log my own debug info?

推荐答案

您可以抛出一个新的异常设定原为内部异常和ELMAH将记录的信息为:

You can throw a new Exception setting the original as the inner exception and ELMAH will log the messages for both:

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.
阅读全文

相关推荐

最新文章