我可以在 Elmah 记录异常之前更改异常吗?
我在 WebForms 应用程序中使用 Elmah,并且希望能够在 Elmah 记录异常之前更改异常。在我的场景中,我的一些依赖组件会抛出异常,这些组件有许多自定义的 InnerExceptions,其中包含 Elmah 忽略的详细信息。因此,我希望有机会迭代 InnerExceptions 并在 Elmah 记录主异常之前将文本详细信息添加到主异常中。
我可以看到如何完全过滤异常,但看起来我无法更改异常并仍然允许记录它。有什么想法吗?
I'm using Elmah in a WebForms app and would like the ability to alter an exception before Elmah logs it. In my scenario there are exceptions being thrown by some of my dependency components that have many custom InnerExceptions with details that Elmah ignores. So I'd like the opportunity to iterate the InnerExceptions and add textual details to the main exception just before Elmah logs it.
I can see how I would filter exceptions entirely, but it doesn't look like I could alter the exception and still allow it to be logged. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您能否处理您的异常,而不是让它们未处理,让 ELMAH 自动拾取,并引发自定义异常,并使用 ELMAH 读取并覆盖的某些属性来显示您想要从自定义异常属性中显示的内容?例如留言
Could you handle your exceptions instead of leaving them unhandled for ELMAH to pick up automatically, and raise a custom exception with some property that ELMAH reads overridden to display what you want from your custom exception properties? e.g. Message
我们通过在本地分叉 Elmah 并根据此 Elmah 问题中的建议添加代码来迭代异常来解决此问题:
http://code.google.com/p/elmah/issues/detail?id=162&can=1&q=data
构建我们自己的版本还允许我们添加几个当前版本的 Elmah 未提供开箱即用的其他功能。
顺便说一句,Elmah 的下一个版本正在开发中 - 至少某些代码库似乎发生了重大变化 - 因此,一旦发布,我需要重新审视这个问题以及我们的其他附加日志记录要求。
We addressed this by forking Elmah locally and adding code to iterate over the exceptions as per the suggestions in this Elmah issue:
http://code.google.com/p/elmah/issues/detail?id=162&can=1&q=data
Building our own version also allowed us to add a couple of other things that the current version of Elmah doesn't provide out of the box.
As an aside the next version of Elmah is in development - there seem to be substantial changes to a least some of the codebase - so I'll need to revisit this problem and our other additional logging requirements once it gets to release.