简体   繁体   中英

Entlib logging block ActivationException when using EmailTraceListener

I have a problem with EmailTraceListener 's configuration. I get ActivationException with an inner exception with this message:

The type TraceListener cannot be constructed. You must configure the container to supply this value.

Here is my app.config logging configuration code :

<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>

If I replace email listener config with a flat file listener config - everything works fine. Where is the mistake in email listener configuration?

The problem is that your All Events category is still hooked up to the FlatFile TraceListener, which no longer exists. Your file also has several other errors which probably should be addressed. I would recommend using the Configuration Console rather than hand coding the configuration, or at least open your configuration in the Configuration Console when you are done to validate it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM