Log4j with xinclude

Hi All,

I am trying to implement logging framework with log4j.xml. Below is a sample of my file. But it is not working as expected. Can anyone tell me how we can do xi:include in log4j2??

<log4j:configuration xmlns:log4j=“http://jakarta.apache.com” xmlns:xi=“http://www.w3.org/2001/XInclude” >

<xi:include href="/home/jack/logging/appenders.xml">
<xi:include href="/home/jack/logging/loggers.xml">


Could you explain the reason for using Log4j as logging framework and not wM product suite using OOTB services and custom implementation?

XML configuration files can include other files with XInclude. Here is an example log4j2.xml file that includes two other files:

<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<configuration xmlns:xi="http://www.w3.org/2001/XInclude"
               status="warn" name="XIncludeDemo">
    <property name="filename">xinclude-demo.log</property>
  <ThresholdFilter level="debug"/>
  <xi:include href="log4j-xinclude-appenders.xml" />
  <xi:include href="log4j-xinclude-loggers.xml" />

<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
  <Console name="STDOUT">
    <PatternLayout pattern="%m%n" />
  <File name="File" fileName="${filename}" bufferedIO="true" immediateFlush="true">
      <pattern>%d %p %C{1.} [%t] %m%n</pattern>

<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
  <logger name="org.apache.logging.log4j.test1" level="debug" additivity="false">
      <KeyValuePair key="test" value="123" />
    <AppenderRef ref="STDOUT" />
  <logger name="org.apache.logging.log4j.test2" level="debug" additivity="false">
    <AppenderRef ref="File" />
  <root level="error">
    <AppenderRef ref="STDOUT" />

Source: Log4j – Configuring Log4j 2

This is a legacy application.

Thanks Mahesh. It works. :slight_smile: