2011-08-04 31 views
6

Khi chúng ta thêm dòng dưới đây để web.config -Làm thế nào để vô hiệu hóa elmah gửi email khi thử nghiệm tại địa phương?

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

ELMAH gửi email trên bất kỳ trường hợp ngoại lệ đó đang xảy ra. Nhưng chúng tôi muốn điều này chỉ xảy ra với trang web trực tiếp được triển khai trên máy chủ web. Và không phải khi chúng tôi đang thử nghiệm các trang web cục bộ trên máy của chúng tôi. Hiện tại nó đang làm điều đó và gửi email khi chúng tôi đang thử nghiệm trang web cục bộ. Có ai biết làm thế nào chúng ta có thể cấu hình nó theo cách đó?

Trả lời

8

Thêm nhật ký email vào Web.Release.config của bạn. Web.config cơ sở của tôi không chứa bất kỳ công cụ nào của Elmah - tất cả đều được thêm vào khi biên dịch với bản phát hành. Nếu bạn biên dịch để phát hành và chạy cục bộ, nó sẽ gửi email và đăng nhập, nhưng một bản sửa lỗi thường xuyên sẽ không.

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> 

Cuối cùng, cần lưu ý rằng Web.config cơ sở của bạn nên có thẻ <configSections> lúc bắt đầu, ngay cả khi nó rỗng:

Web. config

<configuration> 
    <configSections /><!-- Placeholder for the release to insert into --> 
    .... 
Các vấn đề liên quan