Log4j2自定义附加程序:错误尝试附加到未启动的附加程序 [英] Log4j2 Custom appender: ERROR Attempted to append to non-started appender

查看:708
本文介绍了Log4j2自定义附加程序:错误尝试附加到未启动的附加程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在log4j2中创建了一个自定义追加程序。使用自定义追加程序时,出现以下错误: ERROR试图追加到未启动的追加程序。谢谢您的帮助。

I have created a custom appender in log4j2. While using the custom appender, I am getting the following error: "ERROR Attempted to append to non-started appender". Any help is appreciated.

推荐答案

Log4j 2检查每个日志事件是否附加器处于可用状态。您看到的错误是Log4j检测到尚未准备好使用附加程序。

Log4j 2 checks for each log event that the appender is in a useable state. The error you are seeing is that Log4j detects that the appender is not ready to be used.

某些附加器需要进行准备才能使用。 start()生命周期方法是追加程序可以进行初始化的地方。 Log4j不会将事件路由到未处于STARTED状态的附加程序。

Some appenders need to do preparation before they can be used. The start() lifecycle method is the place where appenders can do initialization. Log4j will not route events to an appender that is not in a STARTED state.

如果您的附加程序是通过配置添加的,则Log4j将调用生命周期方法。如果您的附加程序扩展了AbstractAppender,则这将更新状态并且应该足够。否则,请查看AbstractAppender中的生命周期状态管理。

If your appender is added by configuration, Log4j will call the lifecycle method. If your appender extends AbstractAppender, this will update the state and should be sufficient. Otherwise take a look at the lifecycle state management in AbstractAppender.

如果在代码中进行配置,则可能需要显式调用start()。

If you configure in code you may need to call start() explicitly.

这篇关于Log4j2自定义附加程序:错误尝试附加到未启动的附加程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆