Dynamically Change Log File Name in each run

Topics: Logging Application Block
Jan 12, 2015 at 1:43 PM
Edited Jan 12, 2015 at 1:44 PM

After spending a lot of time searching for a suitable code to change the log file name in each run of the code, I found one given by Randy Levy but that uses Enterprise Library 5 and our project is built on version 6.

so the following code is not working any more and frankly speaking I am not very good at coding and getting a hard time to use all the options provided in useful websites.

Can someone please help me rewrite the following section using Enterprise Library 6 or point me towards a way to get help on this particular scenario?

Thanks in advance.
 static void InitializeContainer(SerializableConfigurationSource loggingXmlConfigSource)
            // Create the container
            IUnityContainer container = new UnityContainer();
            container.AddNewExtension<>();// <EnterpriseLibraryCoreExtension>();

            // Configurator will read Enterprise Library configuration 
            // and set up the container
            UnityContainerConfigurator configurator = new UnityContainerConfigurator(container);

            // Configure the container with our own custom logging
            EnterpriseLibraryContainer.ConfigureContainer(configurator, loggingXmlConfigSource);

            // Wrap in ServiceLocator
            IServiceLocator locator = new UnityServiceLocator(container);

            // And set Enterprise Library to use it
            EnterpriseLibraryContainer.Current = locator;
Jan 12, 2015 at 2:27 PM
Thanks to the stimulant and the much needed break that I took before looking at this issue again today. I think I have finally solved this issue. I wasn't very sure that this would be so easy with Enterprise Library 6.0

here is what I did to my code:
            IConfigurationSource configSource = ConfigurationSourceFactory.Create();
            var logSettings = configSource.GetSection(LoggingSettings.SectionName) as LoggingSettings;

            var loggingXmlConfigSource = new SerializableConfigurationSource();
            loggingXmlConfigSource.Add(LoggingSettings.SectionName, logSettings);


            //just this line needs to be added to use the new settings
            Logger.SetLogWriter(new LogWriterFactory(loggingXmlConfigSource).Create());

            Logger.Write("Test", "General");
I ran few instances of the program simultaneously and too my utter delight each one have created its own log file and was writing to it successfully!!
Marked as answer by ubk1004 on 1/12/2015 at 7:27 AM