当使用ELMAH(其辉煌的)是否可以查看的额外信息,你有加入一个例外。

E.g。

Exception ex = new Exception("New exception to use ErrorSignal functionality");
ex.Data.Add("ExtraInfo", "Here is some extra information i would like to be displayed.");
ErrorSignal.FromCurrentContext().Raise(ex);    

当我看到的异常从elmah.axd它似乎并没有显示"ExtraInfo"关键的和价值的信息,只是例外串。

有帮助吗?

解决方案

没有,这是不可能,以查看与当前1.x版本的额外信息。

其他提示

我的解决办法是将信息添加到服务器变量集合,像这样。

var context = HttpContext.Current;
context.Request.ServerVariables["ERROR_CALLING_WEBSERVICE_URI"] = uri;
Elmah.ErrorLog.GetDefault(context).Log(new Error(e, context))

是的,我认为这是一个黑客。结果 对于少量的附加数据的考虑封装误差由@Roma结果的建议 然而,这种方法是特别有用的,你有太多的信息,以放入“封装错误讯息”

在简单的方法来绕过去,是封装的错误。外误差将包含你自定义消息。

string msg = "my custom error message";

ErrorSignal.FromCurrentContext().Raise(
               new Elmah.ApplicationException(msg,ex));

好了,我一直在等待这个被列入太久现在决定做一个自己的它叉,包括功能喽。

您可以在这里找到: https://github.com/boena/elmah-与定制数据

ELMAH使用ToString()方法来获得异常的详细信息。只需覆盖您的自定义异常的ToString()方法,这样它会工作:

“在ELMAH样品异常”

我的异常类:

public class MyCustomException : Exception
{
    public string CustomProperty { get; set; }

    public MyCustomException(string message, string customProperty): base(message)
    {
        this.CustomProperty = customProperty;
    }

    public override string ToString()
    {
        var result = base.ToString();
        var propertyData = String.Format("CustomProperty: {0}", this.CustomProperty);

        return result.Insert(
            result.IndexOf(Environment.NewLine),
            Environment.NewLine + propertyData
            );
    }
}

好了,已经花了一天的这方面的工作,我想我会分享我的解决方案。非常类似于上面Myster的溶液,不同之处我修改由ELMAH代替请求服务器变量,像这样使用的错误的对象:

    public static void LogError(Exception e, IDictionary<string, string> customFields = null)
    {
        var logger = ErrorLog.GetDefault(HttpContext.Current);

        customFields = customFields ?? new Dictionary<string, string>();

        // Used to tell elmah not to log this twice (See global.asax)
        e.Data.Add("Logged", true);

        var error = new Error(e, HttpContext.Current);

        customFields.ForEach(pair => error.ServerVariables.Add(pair.Key, pair.Value));

        logger.Log(error);
    }

然后,根据应用程序来调用logger.LogError:

MVC添加自定义错误滤波器( HTTP ://maheshde.blogspot.ca/2012/09/error-handing-with-mvc-using-custom.html

web表单中的global.asax覆盖的Application_Error

然后,在Global.asax只有一个最后步骤,解除已经被记录的所有错误:

public void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
{
    if (e.Exception.Data.Contains("Logged"))
    {
        if (e.Exception.Data["Logged"].Equals(true)) e.Dismiss();
    }
}

由于它是开放源代码,你可以抢项目和自Elmah为自己的目的:

http://code.google.com/p/elmah/

如果您使用的是MSSQL

  • 看看SqlErrorLog.cs

  • Sql server.sql产生自己的数据库

我也在做同样的,但我需要添加一个额外的随机产生的"错误代码"栏和我将可以使用例外的数据来追踪所有的定义,会议的形式,cookie的信息通常会在超级大的xml领域。我可以改变这式,不确定。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top