简体   繁体   中英

Temporarily Disable logging for log4net

How can I temporarily disable logging of log4net based on the result of my function? example:

if (MyCondition)
{
//Stop logging
}
else
{
//go on, log me...
}

i tried using these codes:

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

to try to disable log4net logging, but the results are the same. log4net is still logging.

Can this be done?

It might be easier to set the logging to "OFF" for all loggers at runtime, then switch them back on afterwards.

Some more info can be found here: http://geekswithblogs.net/rakker/archive/2007/08/22/114900.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM