Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable elmah sending out emails when testing locally?

When we add the below line to web.config -

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

Elmah sends out emails on any exceptions that are occuring. But we want this to only happen with the live site that is deployed on the web server. And not when we are testing the site locally on our machines.Currently it is doing that and sending emails when we are testing the site locally. Does anyone know how we can configure it that way ?

like image 229
Vishal Avatar asked Aug 04 '11 17:08

Vishal


1 Answers

Add the email logging to your Web.Release.config. My base Web.config doesn't contain any Elmah stuff at all - it all gets added in when compiling with release. If you compile for release and run locally, it will email and log, but a regular debug build won't.

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, should note that your base Web.config should have the <configSections> tag at the start, even if it's empty:

Web.config

<configuration>
  <configSections /><!-- Placeholder for the release to insert into -->
  ....
like image 170
Leniency Avatar answered Nov 12 '22 09:11

Leniency