Enterprise Library: Logging Block and Email

自作多情 提交于 2019-11-30 13:58:24

You need to set up an EmailTraceListener in the Logging Application Block.

You can use the Enterprise Library UI but the web.config section ends up looking something like this:

<loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="Default" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add toAddress="admin@company.com" fromAddress="fromemail@company.com"
        subjectLineStarter="" subjectLineEnder="" smtpServer="127.0.0.1"
        smtpPort="25" formatter="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.EmailTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EmailTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Email" />
    </listeners>
    <categorySources>
      <add switchValue="All" name="Default">
        <listeners>
          <add name="Email" />
        </listeners>
      </add>    
    </categorySources>
</loggingConfiguration>

This will work providing your SMTP server is set up correctly. You can use Telnet to check that by sending command line email.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!