1.http://blog.csdn.net/zhangchaoyi1a2b/article/details/77510138 2.use Mavn 3.on the pom.xml <dependencies> <dependency> <groupId>org.apache.logging.lo ...
1.http://blog.csdn.net/zhangchaoyi1a2b/article/details/77510138
2.use Mavn
3.on the pom.xml
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.3</version>
</dependency>
</dependencies>
4.client log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="info" name="Log4jTester" packages="">
<Appenders>
<Socket name="socket" host="localhost" port="9896">
<SerializedLayout />
</Socket>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="socket"/>
<AppenderRef ref="STDOUT"/>
</Root>
</Loggers>
</Configuration>
5.server side log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
</Console>
<File name="MyFile" fileName="log4j2test.log">
<PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n" />
</File>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="MyFile"/>
<AppenderRef ref="STDOUT"/>
</Root>
</Loggers>
</Configuration>
7.start.bat
java -classpath log4j-api-2.3.jar;log4j-core-2.3.jar org.apache.logging.log4j.core.net.server.TcpSocketServer 9896 log4j2.xml
pause
8.log4j 2.9.1 not contains tcpsocketserver