Activation error occured while trying to get instance of type LogWriter, key ""

Topics: Logging Application Block
Aug 9, 2012 at 12:48 PM

Hello,

I am making use of enterprise library 5.0 Logging Application Block to log my application.

But I am continuously getting the following error -- 

Activation error occured while trying to get instance of type LogWriter, key ""

whenever i try to log the log information through the statement: 

  Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(strLogMessage);

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

My app.config file looks like this--
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  </configSections>
  <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
      defaultCategory="Local Log" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add fileName="MUSSLocalTrace.log" header="" footer="" formatter="Text Formatter"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="FlatFile TraceListener" />
      <add source="Enterprise Library Logging" formatter="Text Formatter"
        log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Formatted EventLog TraceListener" />
      <add name="Msmq TraceListener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.MsmqTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.MsmqTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        traceOutputOptions="None" queuePath=".\private$\musstreaminglogs"
        formatter="Text Formatter" messagePriority="Normal" timeToReachQueue="49710.06:28:15"
        timeToBeReceived="49710.06:28:15" recoverable="false" useAuthentication="false"
        useDeadLetterQueue="false" useEncryption="false" transactionType="None" />
    </listeners>
    <formatters>
      <add template="{timestamp(local)}  {message}  {dictionary({key} - {value})}"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Text Formatter" />
    </formatters>
    <logFilters>
      <add categoryFilterMode="AllowAllExceptDenied" type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.CategoryFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Category Filter" />
    </logFilters>
    <categorySources>
      <add switchValue="All" name="Local Log">
        <listeners>
          <add name="FlatFile TraceListener" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events" />
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Formatted EventLog TraceListener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
 
</configuration>

Any idea why i am getting this error?
I tried many solutions that were suggested when i googled, but didn't succeeded



Regards,
Venu 
Aug 9, 2012 at 1:06 PM

The posted configuration looks OK.  The error usually occurs when the configuration is not loaded.  

You mention that the configuration is in app.config so I am assuming that the application is a console or windows application is that correct?  Is the configuration deployed along with myappname.exe program as "myappname.exe.config"?

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

Aug 10, 2012 at 6:45 AM

Yes, your guess is right. The application is a console application. 

The configuration was not deployed. Now i added the app.config file in the console application, and it is creating the "myappname.exe.config" file in 

the bin\debug\ folder. Now, I am getting a different exception as below --

An error occurred creating the configuration section handler for loggingConfiguration: Exception has been thrown by the target of an invocation. (..\LoggingTestClient\bin\Debug\LoggingTestClient.vshost.exe.Config line 6)


Inner Exception -- Exception has been thrown by the target of an invocation.


I copied the same configuration entries as mentioned in the above config file.

Aug 10, 2012 at 7:03 AM

Can you post the full stack trace?

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

Aug 10, 2012 at 7:10 AM

Here is the full stack trace..

 

   at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
   at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
   at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
   at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
   at System.Configuration.ConfigurationManager.GetSection(String sectionName)
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource.DoGetSection(String sectionName) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\SystemConfigurationSource.cs:line 120
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileBasedConfigurationSource.GetSection(String sectionName) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\FileBasedConfigurationSource.cs:line 103
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ConfigSectionLocator.GetRegistrationsInternal(IConfigurationSource configurationSource, Func`3 registrationsAccessor) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\ConfigSectionLocator.cs:line 80
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ConfigSectionLocator.GetRegistrations(IConfigurationSource configurationSource) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\ConfigSectionLocator.cs:line 60
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.CompositeTypeRegistrationsProviderLocator.b__0(ITypeRegistrationsProvider l, IConfigurationSource cs) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\TypeRegistrationsProvider.cs:line 128
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.CompositeTypeRegistrationsProviderLocator.<>c__DisplayClass5.b__4(ITypeRegistrationsProvider l) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\TypeRegistrationsProvider.cs:line 147
   at System.Linq.Enumerable.d__14`2.MoveNext()
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.Unity.UnityContainerConfigurator.RegisterAllCore(IConfigurationSource configurationSource, ITypeRegistrationsProvider rootProvider) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\Unity\UnityContainerConfigurator.cs:line 61
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ChangeTrackingContainerConfigurator.RegisterAll(IConfigurationSource configurationSource, ITypeRegistrationsProvider rootProvider) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\ChangeTrackingContainerConfigurator.cs:line 66
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.ConfigureContainer(ITypeRegistrationsProvider locator, IContainerConfigurator configurator, IConfigurationSource configSource) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 83
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.ConfigureContainer(IContainerConfigurator configurator, IConfigurationSource configSource) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 62
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.CreateDefaultContainer(IConfigurationSource configurationSource) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 122
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.CreateDefaultContainer() in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 108
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.SetCurrentContainerIfNotSet() in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 95
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.get_Current() in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 36
   at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.get_Writer() in e:\Builds\EntLib\Latest\Source\Blocks\Logging\Src\Logging\Logger.cs:line 402
   at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(Object message) in e:\Builds\EntLib\Latest\Source\Blocks\Logging\Src\Logging\Logger.cs:line 62
   at USS.Streaming.Logger.USSLoggerManager.LogMessage(Object objAsynData) in ..\USSLoggerManager.cs:line 860

 

 

Aug 10, 2012 at 7:28 AM

I can't seem to recreate that issue.  Can you send a sample project that reproduces the issue?

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