自定义 Elmah YSOD 数据
我正在将 Elmah 与 ASP.NET 结合使用,并想知道如何将自定义数据(例如会话变量)添加到未处理的异常电子邮件中。
我已经在 Global.asax 文件中尝试了几种处理程序,但似乎找不到合适的处理程序。
I'm using Elmah with ASP.NET and wondering how I would add custom data, such as a session variable, to an unhandled exception email.
I've tried several handlers in the Global.asax file but can't seem to find the right one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为此,我认为您需要修改 Elmah 源 和重新编译。实现它应该不会太难。如果您查看
Elmah.Error
类的构造函数,则会传入HttpContext
,您应该能够从中获取所需的信息,例如 Session 、表单变量等。您可以将自定义字段添加到此数据的Elmah.Error
类中,我认为
Elmah.ErrorMailHtmlFormatter
类是使用构造电子邮件的地方>HtmlTextWriter
,在这里您可以在RenderSummary()
方法中插入代码,以包含您添加到Elmah.Error
的自定义字段。我知道开始使用源代码可能会很痛苦,但我个人认为这是最干净的方法,因为目前没有报告/电子邮件模板的工具,并且最好在生成输出后添加一些东西来更改输出。
For this, I'd think you would need to modify the Elmah source and recompile. It shouldn't be too difficult to achieve. If you have a look in the constructor of the
Elmah.Error
class, theHttpContext
is passed in, from which you should be able to get the info you need, e.g. Session, Form variables etc. You could add custom fields to theElmah.Error
class for this dataI think the
Elmah.ErrorMailHtmlFormatter
class is where the email is constructed using aHtmlTextWriter
, and here you could insert code in theRenderSummary()
method to include the custom fields you added toElmah.Error
.I know it may be a pain to start working with source, but personally I think it's the cleanest way as there currently is no facility for report/email templates, and it's better that bolting on something to change the output after it has been generated.
安德鲁的回答很有帮助,谢谢。我最终执行了以下操作:
Andrew's answer helped a lot, thanks. I ended up doing the following: