使用EmailTraceListener时,Entlib日志记录块ActivationException

时间:2013-07-23 12:02:32

标签: c# .net enterprise-library

EmailTraceListener的配置存在问题。我通过以下消息获得ActivationException内部异常:

  

无法构造TraceListener类型。您必须配置容器以提供此值。

这是我的app.config日志记录配置代码:

<configuration>
  <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  </configSections>
  <loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add 
        name="Email Trace Listener" 
        type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EmailTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.EmailTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        fromAddress="fromAddress@gmail.com"
        toAddress="toAddress@gmail.com"
        smtpServer="smtp.gmail.com" 
        smtpPort="587" 
        authenticationMode="UserNameAndPassword"
        useSSL="true" 
        userName="fromAddress" 
        password="password" 
        formatter="Text Formatter"/>
    </listeners>
    <formatters>
      <add
        type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        template="{severity}{tab}{timestamp(local:dd/MM/yyyy [HH:mm:ss:FFFF] zzz)}{tab}{title}{tab}{message}{tab}
{dictionary([P]: {key}{tab}= {value}
)}"
        name="Text Formatter" />
    </formatters>
    <specialSources>
      <allEvents switchValue="All" name="All Events">
        <listeners>
          <add name="FlatFile TraceListener"/>
        </listeners>
      </allEvents>
      <notProcessed switchValue="All" name="Unprocessed Category"/>
      <errors switchValue="All" name="Logging Errors &amp; Warnings"/>
    </specialSources>
  </loggingConfiguration>
</configuration>

如果我用平面文件监听器配置替换电子邮件监听器配置 - 一切正常。 电子邮件侦听器配置中的错误在哪里?

1 个答案:

答案 0 :(得分:1)

问题是您的所有事件类别仍然连接到不再存在的FlatFile TraceListener。您的文件还有其他一些可能应该解决的错误。我建议使用Configuration Console而不是手动编码配置,或者至少在完成验证后在配置控制台中打开配置。