简体   繁体   English

暂时禁用log4net的日志记录

[英]Temporarily Disable logging for log4net

How can I temporarily disable logging of log4net based on the result of my function? 如何根据函数结果临时禁用log4net的日志记录? 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日志记录,但结果是相同的。 log4net is still logging. log4net仍在记录日志。

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. 在运行时将所有记录器的日志记录设置为“ OFF”可能会更容易,然后再将它们重新打开。

Some more info can be found here: http://geekswithblogs.net/rakker/archive/2007/08/22/114900.aspx 一些更多的信息可以在这里找到: http : //geekswithblogs.net/rakker/archive/2007/08/22/114900.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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