0

我的配置有问题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>

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

4

1 回答 1

1

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

于 2013-07-23T12:46:15.757 回答