Hi, 

  I want to write log to rsyslog

when I use log4j1.x,I use this to define the pattern:

                appender.setLayout(new PatternLayout("%r " + loggerName +" [%t] 
%-5p %C%x - %m %C"));

How can I do the same thing in log4j2.x?

Now I get the message like this:
Nov 24 17:26:59 liaoliuqingdeMacBook-Air.local MyApp  ljh_test message 

I even can not see the level of the log. So how can I set the pattern in 
log4j2.x syslogPattern.

here is my configuration


<?xml version="1.0" encoding="UTF-8"?>
    <Configuration status="warn" name="MyApp" packages="com.lujinhong">
        <Appenders>
        <Syslog name="RFC5424" format="RFC5424" host="10.120.1.1" port="514"
            protocol="UDP" appName="MyApp" includeMDC="true"
            facility="LOCAL7" enterpriseNumber="18060" newLine="true"
            messageId="Audit" mdcId="mdc" id="storm" 
           >
            <LoggerFields>
                <KeyValuePair key="thread" value="%t"/>
                <KeyValuePair key="priority" value="%p"/>
                <KeyValuePair key="category" value="%c"/>
                <KeyValuePair key="exception" value="%ex"/>
                <KeyValuePair key="message" value="%r [%t] %-5p %C%x - %m %C"/>
            </LoggerFields>
          </Syslog>
      </Appenders>
      <Loggers>
        <Logger name="com.mycorp" level="info" />
        <Root level="info">
            <AppenderRef ref="RFC5424"/>
        </Root>
      </Loggers>
    </Configuration>

Reply via email to