views:

382

answers:

3

I have log4net loggers configured to run with my unit tests, but for a few select unit tests that serve as perf tests I want to disable logging. How can I disable (and later re-enable) logging at runtime, basically overriding the logger settings that are in my .config file?

+2  A: 

One simple solution could be to just create a second testproject with different log4net settings...

Arjan Einbu
+1  A: 

I can't answer your question, however when doing performance or load testing you should keep your log settings the same as those you expect in your live system.

Kragen
Basically right - but for profiling (to find a bottleneck) it can be useful to switch of "noise" like logging.
tanascius
I don't expect verbose logging to be turned on during production like I do for running most of my unit tests.
Andrew Arnott
If you depend on your verbose logging to identify and diagnose problems that you might encounter during unit testing, then how do you intend on being able to diagnose and support those issues in production?
Kragen
I depend on verbose logging to understand the cause for bugs that failing tests identify. By the time this library goes to production, I don't expect my customers to be logging verbosely to catch bugs that my job is to iron out before I ship. :)
Andrew Arnott
+2  A: 

on http://osdir.com/ml/windows.dotnet.log4net.user/2004-01/msg00010.html they recommend

To disable all logging set the threshold level for the repository to OFF:

LogManager.GetLoggerRepository().Threshold = LogManager.GetLoggerRepository().LevelMap["OFF"];

To enable logging set the threshold to ALL (this is the default value):

LogManager.GetLoggerRepository().Threshold = LogManager.GetLoggerRepository().LevelMap["ALL"];

Preet Sangha