How to configure concrete LogWriter type for Logger facade?

Topics: Logging Application Block
Nov 23, 2010 at 10:39 PM

Is there a way to configure the concrete LogWriter type used by the Logger facade using the .config only?  If not, what would be the method of doing so through code, if possible?

I've tried unity using both type="LogWriter" and the namespace qualified type as shown below but without success.

      <typeAlias alias="singleton" type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity" />      
      <container name="container">
          <type type="Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter" mapTo="Hsb.EnterpriseLibrary.Logging.AsynchronousLogWriterImpl, Hsb.EnterpriseLibrary.Logging">
            <lifetime type="singleton"/>

Thank you,


Nov 24, 2010 at 1:11 AM

I assume you're using EntLib 4.1 based on the config you posted.   In the 4.1 version, the Logger class explicitly uses the LogWriter class which is a concrete class thus, you cannot configure it to use a different one.  In version 5.0 though, this is possible since it is now an abstract class.  You would use the same registration:

        <register type="Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
mapTo="Hsb.EnterpriseLibrary.Logging.AsynchronousLogWriter, Hsb.EnterpriseLibrary.Logging" />

You would then need to load the container from the config and replace the EnterpriseLibraryContainer.Current object:

IUnityContainer container = new UnityContainer();

EnterpriseLibraryContainer.Current = new UnityServiceLocator(container);

Sarah Urmeneta
Global Technologies & Solutions
Avanade, Inc.