如何让 ELMAH 包含会话值?
注意:我知道避免使用会话的各种原因,但这是我继承的一个项目,所以请跳过任何回复的这一部分:)
因为这是一个已解决的问题,我希望有人可以指出 ELMAH 补丁/branch/fork 包括记录会话数据而不是重新发明轮子。
一件奇怪的事情是 Atif 的一篇旧帖子说他们已经记录了:
http://markmail.org/message/ ncmdgwm5rmzewbwu
评论者 henningst 提到在此处添加会话变量:
http://www.hanselman。 com/blog/ELMAHErrorLoggingModulesAndHandlersForASPNETAndMVCToo.aspx
另一种方法(我宁愿避免)是将值复制到 cookies
我知道一种替代方法是切换到 ELMAH 之外的其他东西(例如 Exceptioneer - 请参阅 http://exceptioneer.com/Public/ExceptioneerAndELMAH.aspx) 但由于这是我目前对 ELMAH 的唯一问题,我宁愿只要有一个打补丁的 ELMAH 就可以了,而不是切换到其他东西。
NOTE: I know the various reasons to avoid using the session, but this is a project I've inherited, so please skip that part of any replies :)
Since it's a solved problem, I'm hoping someone can point to an ELMAH patch/branch/fork that includes logging session data rather than reinventing the wheel.
One weird thing is an older post from Atif that says they're already logged:
http://markmail.org/message/ncmdgwm5rmzewbwu
commenter henningst mentioned adding in the session variables here:
http://www.hanselman.com/blog/ELMAHErrorLoggingModulesAndHandlersForASPNETAndMVCToo.aspx
Another approach (I'd rather avoid) is copying the values into cookies
I know one alternative is to switch to something besides ELMAH (like Exceptioneer - see http://exceptioneer.com/Public/ExceptioneerAndELMAH.aspx) but since this is my only problem with ELMAH at the moment, I'd rather just have a patched ELMAH than switch to something else.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Atif 在 Twitter 上回复称没有已知补丁:
http://twitter.com/raboof/statuses/7229453423< /a>
所以我创建了一个这样做的补丁:
http://twitter.com/manningj/statuses/7231616905
http:// blog.sublogic.com/2009/12/patch-to-enable-session-variable-logging-with-elmah/
Atif replied on twitter to say there's no known patch:
http://twitter.com/raboof/statuses/7229453423
So I created a patch that does so:
http://twitter.com/manningj/statuses/7231616905
http://blog.sublogic.com/2009/12/patch-to-enable-session-variable-logging-with-elmah/
我没有修补 Elmah,而是使用异常数据来完成此操作。在 Global.asax 中,我将额外的数据插入到 Application_Error() 的异常中。 “HistoryStack”是我自己的类,用于记录用户历史记录,包括按钮和选项卡单击:
然后,在 ErrorMail_Mailing() 中,我抓回数据并将其附加到电子邮件中:
现在此数据附加到电子邮件的底部。无需补丁或扩展。
Rather than patching Elmah, I did this with Exception data. In Global.asax I inserted the extra data into the exception on Application_Error(). "HistoryStack" is my own class for recording user history, including button and tab clicks:
Then, in ErrorMail_Mailing() I grabbed the data back and appended it in the email:
Now this data is appended to the bottom of the email. No patches or extensions necessary.
不幸的是,现在可以挖出的旧补丁对于 Elmah 来说有点过时了。这是我在版本 2.0.15523.27 中记录会话变量的方法
基于此处找到的旧补丁:https://storage.googleapis.com/google-code-attachments/elmah/issue-12/comment-5/elmah-sessionVariables.patch
In Error.cs
导入系统.Web.SessionState
查找:
在下面添加:
查找:
在下面添加:
查找:
在下面添加:
查找:
在下面添加:
查找:
在上面添加:
在 ErrorJson.cs 中
查找:
在下面添加:
在 ErrorXml 中.cs
查找:
在下面添加:
查找:
在下面添加:
在 ErrorMailHtmlPage.cshtml
查找:
在上面添加:
在 Visual Studio 中对 ErrorMailHtmlPage.cshtml 进行更改后,右键单击该文件并“运行自定义工具”生成ErrorMailHtmlPage. generated.cs的代码
在ErrorDetailPage.cshtml中
查找(在文件末尾):
在上面添加:
在Visual Studio中对ErrorDetailPage.cshtml进行更改后,右键单击该文件并“运行自定义工具”以生成 ErrorDetailPage. generated.cs 的代码
现在您可以构建(我刚刚使用了项目中包含的 build.cmd 文件)并从 bin 中获取所需的 ddl 文件。
您现在可能还需要修改项目中的 web.config,以包含对 Elmah 的任何引用的版本。如果您使用 Resharper,您只需单击其中的每一个即可修复它们。 (可能应该采取不同的方式来避免这种情况,但我不确定,而且我不太担心弄清楚)
其中一个示例将更
改为
The old patch that can be dug up is unfortunately a little outdated with Elmah now. Here's what I did to log session variables in version 2.0.15523.27
Based on an older patch found here: https://storage.googleapis.com/google-code-attachments/elmah/issue-12/comment-5/elmah-sessionVariables.patch
In Error.cs
Import System.Web.SessionState
Find:
Add below:
Find:
Add below:
Find:
Add below:
Find:
Add below:
Find:
Add above:
In ErrorJson.cs
Find:
Add below:
In ErrorXml.cs
Find:
Add below:
Find:
Add below:
In ErrorMailHtmlPage.cshtml
Find:
Add above:
After making changes to ErrorMailHtmlPage.cshtml in Visual Studio, right click on the file and "Run Custom Tool" to generate the code for ErrorMailHtmlPage.generated.cs
In ErrorDetailPage.cshtml
Find (at the end of the file):
Add above:
After making changes to ErrorDetailPage.cshtml in Visual Studio, right click on the file and "Run Custom Tool" to generate the code for ErrorDetailPage.generated.cs
Now you can build (I just used the build.cmd file that was included with the project) and grab the ddl files from bin that are needed.
You may also have to modify the web.config in your project now to include the version on any references to Elmah. If you're using Resharper you can just click on each of these and fix them. (There's probably a different way this is supposed to be done to avoid this but I'm not sure and I wasn't too worried about figuring it out)
An example of one of them though would be changing
to