Activation error occurs with Logging Application block

Topics: Logging Application Block
May 25, 2010 at 2:15 PM
Edited May 25, 2010 at 9:12 PM

am trying to use the Logging Application block of Enterprise Library 5.0 to log simple message to the Windows event log on Win XP SP3 system using:

 Logger.Write(msg);

 I get the following error message when trying to log:

Microsoft.Practices.ServiceLocation.ActivationException : Activation error occured while trying to get instance of type LogWriter, key ""
  ----> Microsoft.Practices.Unity.ResolutionFailedException : 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)

   ----> System.InvalidOperationException : The type LogWriter cannot be constructed. You must configure the container to supply this value.

  Any help to debug this issue is appreciated. I believe the same code worked with Enterprise Library 4.1 so I keep wondering if Enterprise Library 5.0 works on Win XP SP3?

 Shown below is the config file used with MS Enterprise library 

 

<?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="" tracingEnabled="true" defaultCategory="General">
   
<listeners>
       
<add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
           
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
           
source="Enterprise Library Logging" formatter="Text Formatter"
           
log="Application" machineName="." traceOutputOptions="None" />
   
</listeners>
   
<formatters>
       
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
           
template="Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}"
           
name="Text Formatter" />
   
</formatters>
   
<categorySources>
       
<add switchValue="All" name="General">
           
<listeners>
               
<add name="Event Log Listener" />
           
</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="Event Log Listener" />
           
</listeners>
       
</errors>
   
</specialSources>
</loggingConfiguration>
</configuration>

 

 

May 25, 2010 at 5:38 PM

The config file looks ok at first glance, so my guess would be that the program isn't using the config file you think it's using. Could you post a small but complete sample that reproduces the issue?

 

May 25, 2010 at 7:46 PM

Thanks for your reply. You are absolutely right when you said the program isn't using the config file I think it was using. I was able to use the same config file directly with a NUnit test and it works fine. So, hopefully you will be able to my next question.

I am basically writing a LogAPI dll that uses Logging Application block and includes the App.config file in the project. This API and config file are built and output to an out folder directly.

The Unit tests then use the LogAPI dll from this out folder and that is when I see this issue.

So,

1. Why is the API not able to see the config file although the config file is in the same out folder?

2. Can I rename the App.config file to something else and still have the API working? If yes, how?

Appreciate your help. Thanks

 

May 26, 2010 at 2:10 AM

Class libraries simply don't own configuration files, even if you did deploy a config file in its output folder.  It will use the configuration file of the executable project which references it. 

If you rename App.config, the executable project won't be able to see any configuration file.  If you want to use a different configuration file for entlib blocks, you can make use of a FileConfigurationSource.  For more information on how to do this, please refer to this blog.

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@Avanade.com