ELMAH:ErrorLog_Filtering事件处理IIS7不叫下 [英] Elmah: ErrorLog_Filtering event handler not called under IIS7
问题描述
启用错误日志中过滤ELMAH,并希望以编程方式做了ErrorLog_Filtering事件处理程序。它的工作原理以及在Visual Studio中开发服务器,但只要我去下IIS7(我的本地开发机器或遥控器上我的Web服务器上),该处理程序不叫(错误记录效果很好)。
下面是我一贯的web.config:
<结构> < configSections> < sectionGroup NAME =ELMAH>
<节名称=安全requirePermission =假TYPE =Elmah.SecuritySectionHandler,ELMAH/>
<节名称=错误日志requirePermission =假TYPE =Elmah.ErrorLogSectionHandler,ELMAH/>
<节名称=errorMailrequirePermission =假TYPE =Elmah.ErrorMailSectionHandler,ELMAH/>
<节名称=errorFilterrequirePermission =假TYPE =Elmah.ErrorFilterSectionHandler,ELMAH/>
<节名称=errorTweetrequirePermission =假TYPE =Elmah.ErrorTweetSectionHandler,ELMAH/>
< / sectionGroup>
< / configSections> <&ELMAH GT;
<错误日志类型=Elmah.SqlErrorLog,ELMAH的connectionStringName =ShopMvcConnectionString/>
< / ELMAH> <&的System.Web GT; <&HttpHandlers的GT;
<添加动词=POST,GET,HEAD路径=elmah.axdTYPE =Elmah.ErrorLogPageFactory,ELMAH/>
< / HttpHandlers的> <&的HttpModules GT;
<添加名称=错误日志TYPE =Elmah.ErrorLogModule,ELMAH/>
<添加名称=ErrorFilterTYPE =Elmah.ErrorFilterModule,ELMAH/>
< /&的HttpModules GT; < /system.web> < system.webServer> <模块runAllManagedModulesForAllRequests =真正的>
<添加名称=Elmah.ErrorLogTYPE =Elmah.ErrorLogModule,ELMAHpreCondition =managedHandler/>
<添加名称=Elmah.ErrorFilterTYPE =Elmah.ErrorFilterModulepreCondition =managedHandler/>
< /模块> <&处理GT;
<添加名称=ELMAH路径=elmah.axd动词=POST,GET,HEADTYPE =Elmah.ErrorLogPageFactory,ELMAHpreCondition =integratedMode/>
< /处理器>
< /system.webServer>< /结构>
和我的处理程序在Global.asax中:
公共无效ErrorLog_Filtering(对象发件人,ExceptionFilterEventArgs E)
{
}
原因你在不被IIS 7下所谓的处理,是因为你的命名的模块不同。你把它命名为错误日志
在的System.Web /的HttpModules
然后 Elmah.ErrorLog
在 system.webServer /模块
。
处理模块事件 Global.asax中
通过命名规范,事件处理程序必须在模块名后在配置跟一个下划线( _ $发现被命名为
工作C $ C>)中,随后的事件的名称。 ErrorLog_Filtering
是罚款和注册的名称在的System.Web /的HttpModules
相匹配,并且它正在由<一个回升HREF =http://msdn.microsoft.com/en-us/library/58wxa9w5.aspx相对=nofollow> Visual Studio开发服务器。你只需要确保你匹配所有的名字,它应该在两种环境中工作。
另请参阅:编程记录错误和发送电子邮件
I enable error log filtering within Elmah and want to do it programmatically in a ErrorLog_Filtering event handler. It works well under Visual Studio dev server but as soon as I go under IIS7 (local on my dev machine or remote on my web server), the handler is not called (error logging works well).
Here is my usual web.config:
<configuration>
<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" />
<section name="errorTweet" requirePermission="false" type="Elmah.ErrorTweetSectionHandler, Elmah" />
</sectionGroup>
</configSections>
<elmah>
<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="ShopMvcConnectionString" />
</elmah>
<system.web>
<httpHandlers>
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="Elmah.ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
<add name="Elmah.ErrorFilter" type="Elmah.ErrorFilterModule" preCondition="managedHandler" />
</modules>
<handlers>
<add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
</handlers>
</system.webServer>
</configuration>
and my handler in Global.asax:
public void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
{
}
The reason your handler in not being called under IIS 7 is because you named the module differently. You named it ErrorLog
under system.web/httpModules
and then Elmah.ErrorLog
under system.webServer/modules
.
Handling module events in Global.asax
works via a naming convention where the event handler must be named after the module name as found in the configuration followed by an underscore (_
), followed by the event name. ErrorLog_Filtering
is fine and matches the registered name under system.web/httpModules
and which is being picked up by the Visual Studio Development Server. You just need to make sure that you match up all the names and it should work in both environments.
See also: Programmatically log error and send email
这篇关于ELMAH:ErrorLog_Filtering事件处理IIS7不叫下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!