ELMAH显示异常数据字典中的数据
使用 ELMAH(非常棒)时,可以查看添加到异常中的额外信息。
例如,
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”键和值信息,仅显示异常字符串。
When using ELMAH (which is brilliant) is it possible to view extra information that you have added to an exception.
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);
When I view the exception from elmah.axd it doesn’t seem to show the “ExtraInfo” key and value information, just the exception string.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我的解决方案是将信息添加到服务器变量集合中,如下所示。
是的,我认为这是一个黑客行为。
对于少量的附加数据,请考虑按照@Roma
的建议封装错误
然而,当您有太多信息无法放入“封装的错误消息”时,此方法特别有用
My solution was to add the information to the Server Variables collection like so.
Yes, I Think this is a hack.
For small amounts of additional data consider encapsulating the error as suggested by @Roma
However this method is especially useful where you have too much information to put into an 'encapsulated error message'
解决这个问题的简单方法就是封装错误。 外部错误将包含您的自定义消息。
The simple way to go around, is to encapsulate the error. The outer error will contain you custom message.
不,当前 1.x 版本无法查看额外信息。
No, it is not possible to view the extra information with the current 1.x releases.
好的,所以我已经等待这个功能被包含太久了,并决定自己制作一个分支并自己包含该功能。
您可以在这里找到它: https://github.com/boena/elmah-with-custom -数据
Ok, so I have been waiting for this to be included for too long now and decided to make a own fork of it and include the feature myself.
You can find it here: https://github.com/boena/elmah-with-custom-data
Elmah 使用 ToString() 方法来获取异常详细信息。 只需覆盖您的自定义异常 ToString() 方法,这样它就可以工作:
我的异常类:
Elmah uses ToString() method to get exception details. Just override your custom exception ToString() method and this way it will work:
My exception class:
好吧,花了一天时间研究这个问题,我想我应该分享我的解决方案。 与上面 Myster 的解决方案非常相似,不同之处在于我修改了 elmah 使用的错误对象而不是请求服务器变量,如下所示:
然后,根据您的应用程序调用 logger.LogError:
mvc 添加自定义错误过滤器(http://maheshde.blogspot.ca/2012/09/ error-handing-with-mvc-using-custom.html)
Webforms 覆盖 global.asax 中的 Application_Error
然后,只需在 global.asax 中执行最后一步,忽略已记录的任何错误:
Well, having spent the day working on this, I thought I'd share my solution. Very similar to Myster's solution above, the difference being I modify the error object used by elmah instead of the request server variables, like so:
Then, depending on your application to call logger.LogError:
mvc add a custom error filter (http://maheshde.blogspot.ca/2012/09/error-handing-with-mvc-using-custom.html)
webforms override Application_Error in global.asax
Then, just one final step in the global.asax, dismiss any errors that have already been logged:
由于它是开源的,您可以获取该项目并根据自己的目的自定义 Elmah:
http:// code.google.com/p/elmah/
如果您使用 MSSQL
查看 SqlErrorLog.cs
SQLServer.sql 生成您自己的数据库
我也在做同样的事情,但我需要添加一个额外的随机生成的“错误代码”列,并且我将使用异常数据来跟踪所有自定义、会话、表单,cookie 信息通常位于 uber Large xml 字段中。 我可能会将其更改为 JSON,但还不确定。
Since it is open source, you could just grab the project and customize Elmah for your own purposes:
http://code.google.com/p/elmah/
If you are using MSSQL
take a look at SqlErrorLog.cs
SQLServer.sql to generate your own database
I'm doing the same, but I need to add an extra randomly generated "error code" column and I'll be using exception data to track all the custom, session, form, cookie information that would normally be in the uber large xml field. I may change this to JSON, not sure yet.