Error trying to delete flat log files created during an NUnit test by EntLib 3.0?

Topics: Logging Application Block
Apr 3, 2007 at 6:39 PM
I have a unit test that tests the flat file trace listener by writing a log to a category that is setup to use the flat file trace listener. This works fine and a flat file appears in the specified location. As a clean up operation, I try to delete the flat file log during my TestFixtureTearDown. It doesn't work; I get the following:
Failed to delete ./TestTextFile.log
Exception: System.IO.IOException: The process cannot access the file 'C:\ccm_wa\dev\Connectivity~mvagnoni\Connectivity\Shared\UnitTests\bin\Debug\TestTextFile.log' because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.Delete(String path)
at Cms.Connectivity.Common.UnitTests.LoggingTest.DeleteLogFile(String file) in C:\ccm_wa\dev\Connectivity~mvagnoni\Connectivity\Shared\UnitTests\LoggingTest.cs:line 282

line282: File.Delete(testTextFile);


Also, if I don't close NUnit 2.4 I can't manually delete the file. It says the file is being used by another program. Once I close NUnit 2.4 Gui, I can manually delete the file. Using the Command Line version of NUnit 2.4 to run my tests resulted in the same problems.

What I have done
I did see that in the EntLib Logging Application Block/Logging/Logger.cs->internal static void Reset()

So, I recompiled the Logging.dll, Data.dll, and Common.dll as strong named assemblies, because I needed to make my unit tests:
assembly: InternalsVisibleTo("Blah.Common.Logging.UnitTests, PublicKey=0024...c14ae") in Logging/Assembly.cs to see the Logger.Reset() function during NUnit tests.

I got those 3 dll's to recompile as strong named after much headache. I updated my references to them inside my NUnit test project. Everything is good, I can even see Logger.Reset() in intellisense. I can't however use it. I get a compiler error CS0117: 'Microsoft.Practices.EnterpriseLibrary.Logging.Logger' does not contain a definition for 'Reset'.

Help! Thanks in advance.
Apr 5, 2007 at 9:27 PM
I have had problems deleting a flat file before myself, but I never looked into the problem in-depth.

This obviously does not help with your problem, but you may want to try using the XML Trace Listener or the Rolling Flat File Trace Listener instead. I tend to like them better anyway, but they may not have the problems when trying to delete them. I don't know this for sure, but it is probably worth a shot.




David Hayden
Microsoft MVP C#