Activation error occured while trying to get instance of type LogWriter

Topics: Logging Application Block
Feb 28, 2012 at 2:02 AM

the following code generates an ActivationException, whose message is: Activation error occured while trying to get instance of type LogWriter, key ""

the message of inner exception is:

Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter", name = "(none)".Exception occurred while: while resolving.Exception is: InvalidOperationException - The type Database cannot be constructed. You must configure the container to supply this value.

 

var writer = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();
  <configSections>
    <section name="loggingConfiguration" 
             type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
             requirePermission="true" />
  </configSections>
  <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
    <listeners>
      <add name="Database Trace Listener"
           type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
           listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
           databaseInstanceName="Logging" writeLogStoredProcName="WriteLog"
           addCategoryStoredProcName="AddCategory" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack" />
    </listeners>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Database Trace Listener" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events">
        <listeners>
          <add name="Database Trace Listener" />
        </listeners>
      </allEvents>
      <notProcessed switchValue="All" name="Unprocessed Category">
        <listeners>
          <add name="Database Trace Listener" />
        </listeners>
      </notProcessed>
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Database Trace Listener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>

Feb 28, 2012 at 2:47 AM

It looks like the issue is that the configuration references a database called "Logging" but there is no database called "Logging" configured.  To configure the database create a connection string entry with the name set to "Logging" (you can also do this using the Enterprise Library Configuration Tool):

<connectionStrings>
    <add name="Logging" connectionString="Database=Logging;..." providerName="System.Data.SqlClient" />
</connectionStrings>

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Feb 29, 2012 at 11:39 PM

Dear Randy Levy, thanks for you help, it works!