ELMAH 中的错误信号不适用于 ASP.NET MVC
我的理解是,引发错误信号应该记录我的错误或点击自定义 HandleErrorWithELMAHAttribute 类(取自此 示例),但它两者都没有。
我正在为有问题的控制器使用 HandleErrorWithElmah 装饰器。当涉及到控制器中未处理的异常时,错误日志记录会起作用(我显式调用 LogException 而不是使用 示例)。但是用于处理错误的错误信号功能让我感到困惑。错误信号如何工作...它是否应该做除日志记录之外的其他事情...如果是这样,我如何使用它记录我处理的异常?
这是我用来发出已处理错误信号的代码
ErrorSignal.FromCurrentContext().Raise(new Exception("Some Handled Error"));
下面是我在网络配置中设置的片段
<configSections>
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>
</configSections>
<elmah>
<security allowRemoteAccess="yes" />
<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="Log" />
</elmah>
<httpHandlers>
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
</httpModules>
My understanding is that raising an errorsignal should log my error or hit the custom HandleErrorWithELMAHAttribute class(taken from this example) ,But it does neither.
I am using the HandleErrorWithElmah decorator for the controller in question.The error logging works when it comes to unhandled exceptions in the controller(I am explicitly calling Logexception and not using conditions mentioned in the second code block of example). But the error signalling feature which is to be used for handled errors is keeping me baffled. How does error signalling work...Is it supposed to do something other than Logging...If so how can i use it log my handled exceptions?
This is the code i am using to signal handled errors
ErrorSignal.FromCurrentContext().Raise(new Exception("Some Handled Error"));
And below are snippets of my settings in web config
<configSections>
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>
</configSections>
<elmah>
<security allowRemoteAccess="yes" />
<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="Log" />
</elmah>
<httpHandlers>
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
</httpModules>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将 Elmah 与 .NET MVC 一起使用,并以编程方式引发 Elmah 异常对我来说很有效。我可能在这里抓住了救命稻草,但从此页面 在 Elmah 站点上,Web.config 中包含几行,但上面的示例中没有。
可能您只是没有在代码片段中包含这些行,但我想无论如何我都会把它扔掉
I'm using Elmah with .NET MVC and raising Elmah exceptions programmically works for me. I may be clutching a straws here but from looking at the fourth comment down on this page on the Elmah site there are a couple of lines included in the Web.config that aren't in your example above.
It could be that you just didn't include the lines in your snippet, but I thought I'd throw it out there anyway