ELMAH添加消息通过调用错误记录到提高(五) [英] Elmah add message to error logged through call to Raise(e)

查看:135
本文介绍了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)
{
    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.

这篇关于ELMAH添加消息通过调用错误记录到提高(五)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆