Fluent configuration overrides already configured LogWriter

Topics: Logging Application Block
Jan 5, 2012 at 7:11 AM

Hi ,

I have created a Logging component on top of entlib 5.0 logging application block and all the logging configuration is being done using Fluent inside the code so user need not to provide their configuration or need not to add configuration section required for Logging application block.

I am doing following.

a> Create listneres

b> Create the LogWriter from container

c> Provide the LogWriter object to caller so that they can invoke log methods for categegory which are configured in step a

Now I have got one scenario where the client application already got Logging configuration (loggingConfiguration) provided by entlib and they are loading their logwriter through app.config data and same time when they using our Logging component , our LogWriter ovverrides their configuration which creates problem..

My question , is there any way where I can attach trace listners to the already created LogWriter..so that both app.config section and Fluent config will work together..

Please let me know for any more data required to analyze the issue.



Jan 5, 2012 at 7:45 AM
Edited Jan 5, 2012 at 7:47 AM

Since it sounds like you are managing your own LogWriters I would create my own UnityContainer and store all my log configuration in my own private container without changing the EnterpriseLibraryContainer.  This way you insulate your LogWriters from any configuration already present (if you update the EnterpriseLibraryContainer you could change the client's configuration).

    public class MyLogger
        private static IUnityContainer container;

        static MyLogger()
            var builder = new ConfigurationSourceBuilder();

                     .SendTo.EventLog("Formatted EventLog TraceListener")
                       .FormatWith(new FormatterBuilder()
                         .TextFormatterNamed("Text Formatter")
                           .UsingTemplate("Timestamp: {timestamp}...{newline})}"))

            var configSource = new DictionaryConfigurationSource();

            var extension = new EnterpriseLibraryCoreExtension(configSource);
            container = new UnityContainer();

        public LogWriter GetLogger()
            return GetLogger("");

        public LogWriter GetLogger(string loggerName)
            return container.Resolve<LogWriter>(loggerName);

Randy Levy
Enterprise Library support engineer

Jan 5, 2012 at 1:25 PM

Thanks Randy ..It works..nice to see your prompt response.