问题描述
如何在log4j中使用AsyncAppender以便将日志消息写入Web服务?我应该创建自己的Appender来扩展AsyncAppender还是将自定义附加程序附加到AsyncAppender?如果第二种选择是正确的,我应该在哪里使用AsyncAppender对象?有例子吗?
How to use AsyncAppender in log4j in order to write log message to the web service? Should I create my own Appender which would extend AsyncAppender or just attach custom appenders to the AsyncAppender? If the second choice is correct, where should I take the AsyncAppender object? Is there any example?
推荐答案
回答我自己的问题.
在log4j配置文件(通常是log4j.xml或log4j.properties)中,我们应该定义AsyncAppender,它引用一个真实的追加程序(可能是我们自己定义的类,就像我这样).
In the log4j config file(usually it's log4j.xml or log4j.properties) we should define AsyncAppender which would refer to a real appender(it may be our own defined class like in my case).
因此,我编写了一个WebServiceAppender类,该类扩展了AppenderSkeleton并实现了3个抽象方法.主要方法是附加",它连接到Web服务并将所有信息发送给它.就是这样.
So I wrote a WebServiceAppender class which extends AppenderSkeleton and implements 3 abstract methods. The main method is "append" which connects to the web service and sends all the information to it. That's it.
这篇关于如何在log4j中使用AsyncAppender?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!