views:

196

answers:

1

Let me explain my scenario first:

  1. I have around 2000 tests to run, which take about 30 seconds in NUnit
  2. I want to find out what's taking the time
  3. I open Ants Profiler, and get it to profile the NUnit TestRunner, and load my test dll into the TestRunner
  4. I then run the tests...

However, running the tests whilst profiling takes a lot longer (about 5 minutes to run all the tests, rather than 30 seconds). When i look through the timings in Ants Profiler, it seems log4net is being called in a lot of places, which seems to be taking up the time.

So, this is my question: how do i stop log4net logging stuff when i'm running the tests in this manner?

I can find 3 config files:

  1. In the test dll folder, there's a config.log4net file. I've put <level value="OFF" /> in there, and deleted all the appender sections
  2. In the test runner folder, there's a nunit.exe.config, and a nunit-console.exe.config file - i've put <level value="OFF" /> in both of those.
  3. I can't find any config files to play with in the ants profiler folder.

None of this seems to work, looking through the profile results i can see log4net being called, and it's definitely calling methods to output the logging information.

+1  A: 

In the test setup, get the root logger and set it's log level to OFF.

Aaron Digulla
The logs are configured in xml. I could in theory set the level to off in the setup method, but there's a lot of fixtures (and a lot of setup methods). I'd prefer to be able to configure the logger once. The approach suggested here will mean i have to recompile my test projects to change the configuration, and all test projects will have to manually turn off logging. It seems there should be a simpler way to do this.
David_001
Log4* wasn't designed for testing :( My solution is to have a common base class for all tests (which also defines a couple of extra asserts) and which can do these kinds of tricks.
Aaron Digulla
Oh, and open a bug report against log4net. Maybe they can allow you to read more than a single config file. With log4j, I can say `-Dlog4j.configuration=log4j-null.xml` to chose a file I want globally.
Aaron Digulla