title: Unable to implement TcpSocketServer in Log4j2
body: <p>I am trying to write logs in a SpringBoot application to a remote server using <a href="https://logging.apache.org/log4j/2.0/log4j-core/apidocs/org/apache/logging/log4j/core/appender/SocketAppender.html" rel="nofollow noreferrer">SocketAppender</a> in Log4j2. First I run the listener application (which is also a spring boot application) where I have implemented the <a href="https://logging.apache.org/log4j/log4j-2.7/log4j-core/apidocs/org/apache/logging/log4j/core/net/server/TcpSocketServer.html" rel="nofollow noreferrer">TcpSocketServer</a> and then I run my main application. I am getting the the following errors. Main app runs on localhost:8080 and listener app runs on localhost:9600. </p>
  
  <p>Am I doing it the right way? How can I correctly implement this logging? I could not find a proper example online. </p>
  
  <blockquote>
    <p>In listener application</p>
  </blockquote>
  
  <pre><code>java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens
  </code></pre>
  
  <blockquote>
    <p>In main application </p>
  </blockquote>
  
  <pre><code>2019-06-20 17:24:28,091 main ERROR Unable to write to stream 
  TCP:localhost:9600 for appender socket-appender: org.apache.logging.log4j.core.appender.AppenderLoggingException: Error writing to TCP:localhost:9600
  2019-06-20 17:24:28,092 main ERROR An exception occurred processing Appender socket-appender org.apache.logging.log4j.core.appender.AppenderLoggingException: Error writing to TCP:localhost:9600
  Caused by: java.net.SocketException: Broken pipe (Write failed)
  </code></pre>
  
  <p><strong>My Implementation</strong></p>
  
  <blockquote>
    <p>Log4j2 configurations in main app</p>
  </blockquote>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Configuration status="debug"&gt;
      &lt;Appenders&gt;
          &lt;Socket name="socket-appender" host="localhost" port="9600"&gt;
              &lt;JsonLayout properties="true"/&gt;
          &lt;/Socket&gt;
      &lt;/Appenders&gt;
      &lt;Loggers&gt;
          &lt;AsyncLogger  name="socket-appender" level="info"&gt;
              &lt;AppenderRef ref="socket-appender"/&gt;
          &lt;/AsyncLogger&gt;
          &lt;AsyncRoot level="info"&gt;
              &lt;AppenderRef ref="socket-appender"/&gt;
          &lt;/AsyncRoot&gt;
      &lt;/Loggers&gt;
  &lt;/Configuration&gt;
  </code></pre>
  
  <blockquote>
    <p>Log4j2 configurations in listener app</p>
  </blockquote>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Configuration status="debug" name="SocketServer"&gt;
      &lt;Appenders&gt;
          &lt;RollingRandomAccessFile name="Rolling-Random-Access-File-Appender"
                                   fileName="logs/rollingrandomaccessfile.log"
                                   filePattern="archive/logs/rollingrandomaccessfile.log.%d{yyyy-MM-dd-hh-mm}.gz"&gt;
              &lt;PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n"/&gt;
              &lt;Policies&gt;
                  &lt;SizeBasedTriggeringPolicy size="1 KB"/&gt;
              &lt;/Policies&gt;
              &lt;DefaultRolloverStrategy max="30"/&gt;
          &lt;/RollingRandomAccessFile&gt;
      &lt;/Appenders&gt;
      &lt;Loggers&gt;
          &lt;AsyncLogger&gt;
              &lt;AppenderRef ref="Rolling-Random-Access-File-Appender"/&gt;
          &lt;/AsyncLogger&gt;
          &lt;AsyncRoot level="info"&gt;
              &lt;AppenderRef ref="Rolling-Random-Access-File-Appender"/&gt;
          &lt;/AsyncRoot&gt;
      &lt;/Loggers&gt;
  &lt;/Configuration&gt;
  </code></pre>
  
  <blockquote>
    <p>TcpSocketServer Implementation in listener app</p>
  </blockquote>
  
  <pre><code>package com.springReceiver.receiveFromSocket;
  
  import org.apache.logging.log4j.core.net.server.ObjectInputStreamLogEventBridge;
  import org.apache.logging.log4j.core.net.server.TcpSocketServer;
  
  import java.io.IOException;
  import java.io.ObjectInputStream;
  
  class Receiver {
  
      void writeLogs(){
  
          TcpSocketServer&lt;ObjectInputStream&gt; server = null;
          try {
              server = new TcpSocketServer&lt;&gt;(9600,new ObjectInputStreamLogEventBridge());
              server.run();
          }
          catch (IOException e)
          {
              e.printStackTrace();
          }
  
  
      }
  }
  </code></pre>