How to temporarily disable log4net logging for perf tests?
-
06-07-2019 - |
Question
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?
Solution
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"];
OTHER TIPS
One simple solution could be to just create a second testproject with different log4net settings...
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.