Sitecore 500 错误记录/警报
问题
目前,我希望提供一个自定义 500 错误页面,并记录并警告 Web 管理员所遇到的情况(什么 URL、堆栈跟踪、时间戳等)。
我尝试在系统配置下定义自定义http错误,但没有命中错误页面。 我能够处理 404 及其相关错误(layoutnotfound)。
问题
我应该拦截 global.asax 中的上下文来处理 500 错误并返回自定义页面吗? Sitecore 是否有其他方法可以实现我正在寻找的目标?
主要是,我正在寻找使用 Sitecore 记录/警报 500 个错误的最佳实践
Problem
Currently, I'm looking to serve a custom 500 error page as well as log and alert a web master about the condition that was hit (What URL, stack trace, timestamp, etc.).
I tried defined custom http errors under system configuration, but the error pages were not hit.
I am able to handle 404s and their related errors (layoutnotfound).
Question
Should I intercept the context in global.asax to handle the 500 errors and return a custom page? Is there another way with Sitecore to achieve what I'm looking for?
Mainly, I'm looking for best practice of logging / alerts for 500 errors with Sitecore
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试使用 ELMAH。
这里是一篇关于将其与网站核心。
Try using ELMAH.
Here is an article on using it with Sitecore.
Elmah 很棒并且做得很好。您还可以使用 log4net 来记录异常。您要做的就是在 global.asax 中添加一个 application_error 方法,您就可以跟踪发生的所有错误。您还可以添加不同的附加程序,并将消息记录在日志文件、数据库中并通过电子邮件发送。
以下是记录错误的代码,并包含一些附加信息,例如 url 和当前 sitecore 项目:
如果您想要一个简单的解决方案,我建议使用 Elmah。如果您想要更多的控制和更多的日志记录选项,您应该使用自定义的 log4net 解决方案。
Elmah is great and does a good job. You can also use log4net to log exceptions. All you do is add an application_error method in global.asax and you can track all the errors that occur. You can also add different appenders and can log messages in a log file, database and email them.
Here is the code that logs the error and includes some additional information like url and Current sitecore item:
If you want an easy solution I would recommend going with Elmah. If you want to have more control and more logging options you should go with a custom log4net solution.
在这一点上...请注意,本地访问时自定义错误的行为有所不同。另外,默认情况下,您需要为这些页面使用物理文件(而不是 sitecore 页面)。您需要了解返回超过 200 的状态代码时的 IIS 行为,以及它如何依赖于 web.config 和(如果在集成模式下运行)该部分中的配置。特别是,请参阅下面第一个链接中间的流程图。
http:// learn.iis.net/page.aspx/267/how-to-use-http-detailed-errors-in-iis-70/
http://www.iis.net/ConfigReference/system.webServer/httpErrors
http://msdn.microsoft.com/en- us/library/ms689487(v=VS.90).aspx
您可能还希望将 RequestErrors.UseServerSideRedirect 设置更改为“true”,以提供更好的 http 响应而无需重定向。
On that particular point...Be aware that custom errors behave differently when accessed locally. Also, by default you need to use physical files (not sitecore pages) for these pages. You need be aware of IIS behaviour when returning status codes over 200 and how it is dependant on the configuration within web.config and (if running in integrated mode) the section. In particular, see the flow chart half way down the first link below.
http://learn.iis.net/page.aspx/267/how-to-use-http-detailed-errors-in-iis-70/
http://www.iis.net/ConfigReference/system.webServer/httpErrors
http://msdn.microsoft.com/en-us/library/ms689487(v=VS.90).aspx
You might also want to change the RequestErrors.UseServerSideRedirect setting to "true" to provide better http responses without redirects.