当我们将以下行添加到web.config -
时<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
Elmah发送有关正在发生的任何异常的电子邮件。但我们希望这只发生在Web服务器上部署的实时站点。而不是当我们在我们的机器上本地测试网站时。当前它正在这样做并在我们在本地测试网站时发送电子邮件。有谁知道我们如何配置它?
答案 0 :(得分:8)
将电子邮件日志记录添加到Web.Release.config中。我的基础Web.config根本不包含任何Elmah东西 - 在使用release进行编译时都会添加它们。如果你编译发布并在本地运行,它将通过电子邮件发送和登录,但是常规的调试版本不会。
<强> Web.Release.config 强>
<configSections>
<sectionGroup name="elmah" xdt:Transform="Insert">
<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>
<connectionStrings>
<clear/>
<add xdt:Transform="Insert" name="ErrorLogs" connectionString="...." />
</connectionStrings>
<elmah xdt:Transform="Insert">
<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="ErrorLogs" />
<security allowRemoteAccess="0" />
<errorMail ...Email options ... />
</elmah>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<httpModules xdt:Transform="Insert">
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
</httpModules>
</system.web>
<system.webServer>
<modules xdt:Transform="Insert" runAllManagedModulesForAllRequests="true">
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
</modules>
</system.webServer>
</configuration>
最后,请注意您的基础Web.config在开头应该有<configSections>
标记,即使它是空的:
<强>的Web.config 强>
<configuration>
<configSections /><!-- Placeholder for the release to insert into -->
....