Fluent config in .NET 4

Topics: Logging Application Block
Aug 13, 2010 at 8:38 AM

I'm not sure if I'm doing something wrong or if this is some bug with Entlib 5, maybe with .NET 4.  I have a bare bones app.config configuration:

 <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
    <listeners>
      <add name="LogFileListener" 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="logfile.log" footer="" formatter="Text Formatter"
        header="" rollFileExistsBehavior="Increment" rollInterval="Day"
        maxArchivedFiles="5" />
    </listeners>
    <formatters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        template="[{category} ({timestamp})] {message}" name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="LogFileListener" />
        </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="LogFileListener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>

And I have a fairly simple test case for the Fluent configuration:
 
var builder = new ConfigurationSourceBuilder();
builder.ConfigureLogging()
  .LogToCategoryNamed("stuff2")
  .SendTo.SharedListenerNamed("LogFileListener");
var configSource = new DictionaryConfigurationSource();
builder.UpdateConfigurationWithReplace(configSource);
EnterpriseLibraryContainer.Current  = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);
Logger.Write("Hello World","stuff2");
 
No matter if I log to "stuff2" or the default category or with various other test cases, I always get:
        Resolving System.Diagnostics.TraceListener,LogfileListener
 ---> System.InvalidOperationException: The type TraceListener cannot be constru
cted. You must configure the container to supply this value.
   at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardT
ypeIsNonPrimitive(IBuilderContext context, SelectedConstructor selectedConstruct
or) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategie
s\BuildPlan\DynamicMethod\Creation\DynamicMethodConstructorStrategy.cs:line 289
   at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBui
ldUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\S
rc\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\Creation\DynamicMethodConstr
uctorStrategy.cs:line 71
Any ideas?
Thanks
Aug 13, 2010 at 9:14 AM
Edited Aug 13, 2010 at 9:31 AM

I copied your config and the code you posted.  I didn't encounter any errors.  Are you sure this is the whole content of your loggingConfiguration? What assemblies did you referenced?   This app.config file is the configuration file of an executable project and not defined in a class library project?

 

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