Enterprise Library Logging Application Block

Topics: Logging Application Block
Oct 27, 2010 at 3:08 AM
Edited Oct 27, 2010 at 3:56 AM

Recently I decided to switch from version 4.0 to version 5.0, however, there is a problem to initialize the LogWritter by the application. Below is my app.config that configured with the enterprise library configuration tool, whenever I create the LogWritter, the application throw exception:

 

<?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="false" />
  </configSections>
  <loggingConfiguration name="Logging Application Block" tracingEnabled="false"
    defaultCategory="EventLogging" logWarningsWhenNoCategoriesMatch="true"
    revertImpersonation="false">
    <listeners>
      <add name="EventLogFileListener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        fileName="Event.log" footer="" formatter="EventContentFormatter"
        header="" rollFileExistsBehavior="Increment" rollSizeKB="2048" />
    </listeners>
    <formatters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        template="My Template Details"
        name="EventContentFormatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="EventLogging">
        <listeners>
          <add name="EventLogFileListener" />
        </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="EventLogFileListener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
</configuration>

 

Below is the exception when the application try to initialize the LogWriter:

An error occurred creating the configuration section handler for loggingConfiguration: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) (%MyApplicationDirectory%\MyApplication.vshost.exe.Config line 4)

However, there is a workaround, the application success to initialize the LogWritter, and the content could be log successfully when I remove the following information in the config file:

 

Version=5.0.414.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false"

 

The configuration file looks like this after the modification:

 

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging" />
  </configSections>
  <loggingConfiguration name="Logging Application Block" tracingEnabled="false"
    defaultCategory="EventLogging" logWarningsWhenNoCategoriesMatch="true"
    revertImpersonation="false">
    <listeners>
      <add name="EventLogFileListener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
        fileName="Event.log" footer="" formatter="EventContentFormatter"
        header="" rollFileExistsBehavior="Increment" rollSizeKB="2048" />
    </listeners>
    <formatters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging"
        template="My Formatters Details"
        name="EventContentFormatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="EventLogging">
        <listeners>
          <add name="EventLogFileListener" />
        </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="EventLogFileListener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
</configuration>

The annoying part is, whenever I modify the logging configuration using the Enterprise Library Configuration Tools, all the removed information will come back. Anyone could please guide me what is the problem with those information removed? I have checked, the referenced assembly have the same version as stated in the information removed.

 

 

Oct 27, 2010 at 3:42 AM
Edited Oct 27, 2010 at 3:43 AM

Those attributes shouldn't be a source of problem if you're referencing the correct version of the assemblies.  In your case, it seems your application is  loading a different version of entlib assemblies since it complains about a mismatch.

Check your entlib references.  Check the Version property if it reflects 5.0.414.0.  See also if the Copy Local property is set to True.  If it is False, then it is trying to load the assembly from GAC.  It should be set to  True if you added the reference from a specific folder.

Another possible explanation is that you might be referencing a non-entlib assembly which in turn, references a different version of entlib.

 

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

Oct 27, 2010 at 4:07 AM
Edited Oct 27, 2010 at 4:15 AM

That was what come into my mind at first, what I have did to troubleshoot was, I go to my EntLib50Src\bin directory installed in my machine, copy the assemblies below to my project references folder, and add reference the dll from that folder, Copy Local were set to True for all 3 assemblies. Unluckily, the problem still exists.

  • Microsoft.Practices.EnterpriseLibrary.Common.dll
  • Microsoft.Practices.EnterpriseLibrary.Logging.dll
  • Microsoft.Practices.ServiceLocation.dll

To add-on, the version both all 3 assemblies are 5.0.414.0 except ServiceLocation

This is the only Enterprise Library 5.0 I installed, so i think there won't be other version in my machine.

Oct 27, 2010 at 4:15 AM
Edited Oct 27, 2010 at 4:16 AM

That's what's causing the problem.  The assemblies from EntLib50Src\bin are not the same as what you should be using which is from \Program Files\Microsoft Enterprise Library 5.0\Bin.  They have the same code base but the latter are the strongly-named ones being used by the EntLib config tool integrated in Visual Studio and those which you open from Start -> Programs -> Microsoft Patterns and Practices......

 

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

Oct 27, 2010 at 4:17 AM
Edited Oct 27, 2010 at 4:18 AM

So do you mean I must reference from the \Program Files\Microsoft Enterprise Library 5.0\Bin rather than my own reference folder?

 

Because I did the same thing with enterprise library 4, there isn't any issue like this before...

Oct 27, 2010 at 4:21 AM
AvanadeSupport wrote:

That's what's causing the problem.  The assemblies from EntLib50Src\bin are not the same as what you should be using which is from \Program Files\Microsoft Enterprise Library 5.0\Bin.  They have the same code base but the latter are the strongly-named ones being used by the EntLib config tool integrated in Visual Studio and those which you open from Start -> Programs -> Microsoft Patterns and Practices......

 

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

Thanks you for your support and explanation, the problem solved when I reference from the location you mentioned, rather than the EntLib50Src\bin

Aug 10, 2012 at 4:12 PM
Line 2:  <configuration>
Line 3:    <configSections>
Line 4:      <section name="loggingConfiguration" 
Line 5:               type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
Line 6:               requirePermission="true" /> 

However, there is a workaround, the application success to initialize the LogWritter.

Parser Error Message: An error occurred creating the configuration section handler for loggingConfiguration: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

i check my GAC as well as Ent5 version too. Is any one can help me out

-Ram

Aug 11, 2012 at 10:48 AM

Perhaps the deployed assemblies are version 5.0.505.0 and not 5.0.414.0.  Run Fuslogvw.exe (Assembly Binding Log Viewer) to determine what assemblies are being probed and verify the deployed versions (and potentially strong name especially if using custom builds of Enterprise Library).

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