2011-08-04 3 views
6

我々はweb.configファイルに以下の行を追加します -ローカルでテストするときにメールを送信するelmahを無効にするにはどうすればよいですか?

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

ELMAHはoccuringされているすべての例外にメールを送信します。しかし、Webサーバーに配備されているライブサイトでのみこれを実行したいと考えています。私たちのマシンでローカルにサイトをテストしているときではありません。現時点では、サイトをローカルでテストしているときに電子メールを送信しています。誰もがそのように設定する方法を知っていますか?

答えて

8

Web.Release.configに電子メールログを追加します。私のベースのWeb.configにはElmahのものは一切含まれていません。リリースでコンパイルすると、すべてが追加されます。リリース用にコンパイルしてローカルで実行すると、電子メールとログに記録されますが、通常のデバッグビルドでは実行されません。

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 --> 
    .... 
関連する問題