Log files still in use after loggin

Topics: Logging Application Block
Dec 23, 2010 at 3:11 PM


this code:

LogWriter writer = null;

            ConfigurationSourceBuilder builder = new ConfigurationSourceBuilder();
            //Create new source
            DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource();

            //Replace the old configuration with the new one

            //Update the current container
            EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configurationSource);

            //Update the writer object with the current instance of the LogWriter
            writer = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();

            writer.Write("Hallo""UnitTest", 0, 0, TraceEventType.Warning);


throws an exception System.IO.IOException: The process cannot access the file 'd:\Temp\test1.xml' because it is being used by another process.

How can this be avoided?

Best regards,


Dec 26, 2010 at 12:31 AM
Edited Dec 26, 2010 at 12:33 AM

You can open the file using the code below:

using(FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
        using(StreamReader reader = new StreamReader(fs))
               string log =  reader.ReadToEnd();

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.