本文介绍了使用 syslog appender 和 RFC5424 的 Log4j2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试向远程 Linux syslog 写入一些消息时,我使用带有 appender syslog 和 format=RFC5424 的 log4j2,以及 BSD.我的配置文件如下:

When I try to write some message to a remote Linux syslog, I use log4j2 with appender syslog and format=RFC5424, and BSD.My configuration file is as follows:

<?xml version="1.0" encoding="UTF-8"?>
    <Configuration status="warn" name="MyApp" packages="">
        <Appenders>
            <Syslog name="bsd" host="9.115.114.133" port="514" protocol="UDP" facility="local5"/>
            <Syslog name="RFC5424" format="RFC5424" host="9.115.114.133"
                protocol="UDP" appName="MyApp" includeMDC="true"
                 facility="LOCAL5" enterpriseNumber="18060" newLine="true"
                  messageId="Audit" id="App"/>
         </Appenders>
         <Loggers>
         <Logger name="test.main" level="warn">
         <AppenderRef ref="RFC5424"/>
         </Logger>
         <Root level="error">
        <AppenderRef ref="bsd"/>
        </Root>
        </Loggers>

当我运行测试程序时,总是出现如下错误:引起:java.lang.IllegalArgumentException:未提供结构化的 id 名称在 org.apache.logging.log4j.message.StructuredDataId.(StructuredDataId.java:92)在 org.apache.logging.log4j.core.layout.Rfc5424Layout.(Rfc5424Layout.java:139)在 org.apache.logging.log4j.core.layout.Rfc5424Layout.createLayout(Rfc5424Layout.java:657)在 org.apache.logging.log4j.core.appender.SyslogAppender.createAppender(SyslogAppender.java:133)……还有 20 个

When I running a testing program, I always got the error as follows:Caused by: java.lang.IllegalArgumentException: No structured id name was supplied at org.apache.logging.log4j.message.StructuredDataId.(StructuredDataId.java:92) at org.apache.logging.log4j.core.layout.Rfc5424Layout.(Rfc5424Layout.java:139) at org.apache.logging.log4j.core.layout.Rfc5424Layout.createLayout(Rfc5424Layout.java:657) at org.apache.logging.log4j.core.appender.SyslogAppender.createAppender(SyslogAppender.java:133) ... 20 more

2014-11-10 03:21:46,252 错误 为 Appender 中的 Syslog 返回空对象.2014-11-10 03:21:46,267 错误无法找到记录器 test.main 的附加程序 RFC5424

2014-11-10 03:21:46,252 ERROR Null object returned for Syslog in Appenders.2014-11-10 03:21:46,267 ERROR Unable to locate appender RFC5424 for logger test.main

我怎样才能摆脱这个错误?谢谢.

How could I get rid of this error? Thanks.

推荐答案

您需要包含 mdcId 属性:

<Syslog name="RFC5424" format="RFC5424" host="9.115.114.133"
        protocol="UDP" appName="MyApp" mdcId="mdc" includeMDC="true"
        facility="LOCAL5" enterpriseNumber="18060" newLine="true"
        messageId="Audit" id="App"/>

这篇关于使用 syslog appender 和 RFC5424 的 Log4j2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 05:24