简体   繁体   English

事件发生时重新加载Log4j.xml文件配置

[英]Reload the Log4j.xml file configuration on event occurance

I have complete the simple configuration of Log4j2 latest version library(with log4j2.xml configuration file) which working fine. 我已经完成了Log4j2最新版本库的简单配置(带有log4j2.xml配置文件),可以正常工作。

Now i want to update/reset configuration whenever the update event fire i as check on internet there is no such API available in the latest version on log4j2 jar.eg in old api there is method called 现在我想在更新事件触发时更新/重置配置,因为我在Internet上检查在log4j2 jar的最新版本中没有这样的API。例如,在旧api中有一种称为

   LogManager.resetConfiguration()

So how i can reset the configuration or refresh log4j2 configuration runtime? 那么我如何可以重置配置或刷新log4j2配置运行时?

Log4j 2 allows you to specify a monitorInterval. Log4j 2允许您指定monitorInterval。 Log4j will check to see if the configuration file has been modified after the number of seconds specified in the monitorInterval have passed. 在MonitorInterval中指定的秒数过去之后,Log4j将检查配置文件是否已被修改。 If your file has changed it will be reloaded. 如果您的文件已更改,它将被重新加载。

If you do not want to use the automatic method then you need to get the LoggerContext (part of the internal part of Log4j) and call its reconfigure method. 如果您不想使用自动方法,则需要获取LoggerContext(Log4j内部部分的一部分)并调用其reconfigure方法。

final LoggerContext ctx = (LoggerContext) LogManager.getContext(false); ctx.reconfigure();

我不确定是否从文件中重新加载配置,但是您可以尝试

LogManager.getContext(false).updateLoggers();

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

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