How to disable elmah email sending during local testing?

When we add the following line to web.config -

<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" /> 

Elmah sends emails for any exceptions that occur. But we want this to happen only with a live site that is deployed to a web server. And not when we test the site locally on our machines. He currently does this and sends emails when we test the site locally. Does anyone know how we can configure it this way?

+6
source share
1 answer

Add the email to your Web.Release.config. My Web.config database does not contain any Elmah materials at all - all this is added when compiling with the release. If you compile for release and run locally, it will send email and register, but there will be no regular debug build.

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> 

Finally, it should be noted that your base Web.config should have a <configSections> at the beginning, even if it is empty:

Web.config

 <configuration> <configSections /><!-- Placeholder for the release to insert into --> .... 
+8
source

Source: https://habr.com/ru/post/894310/


All Articles