title: Remote Logging using Log4j2
body: <p>So i have this task to log activities to a file, but it has to be done 
  remotely on the server side, Remote logging.</p>
  
  <blockquote>
    <p>NOTE : Remote Logging has to be in latest version of <strong>Log4j2(2.10)</strong></p>
  </blockquote>
  
  <p>My task was simple</p>
  
  <ol>
  <li>Send logging info to a port.</li>
  <li>Log info from port to a file.</li>
  </ol>
  
  <p>My Discoveries</p>
  
  <ol>
  <li>Socket Appender exist which help send info to a port. This is it, you dont need to create a client side code or anything. </li>
  </ol>
  
  <p><strong>Socket appender configuration in <em>log4j2.properties</em></strong></p>
  
  <pre><code>appender.socket.type = Socket
  appender.socket.name= Socket_Appender
  appender.socket.host = "IP address"
  appender.socket.port = 8101
  appender.socket.layout.type = SerializedLayout
  appender.socket.connectTimeoutMillis = 2000
  appender.socket.reconnectionDelayMillis = 1000
  appender.socket.protocol = TCP
  </code></pre>
  
  <p>Adapting from <a href="https://howtodoinjava.com/log4j/log4j-socketappender-and-socket-server-example/" rel="nofollow noreferrer">here</a>. But this is also log4j 1.x adaptation.</p>
  
  <ol>
  <li>I found out that before log4j 2.6 to listen to a port we used TcpSocketServer which started a server using LogEventBridge<a href="https://stackoverflow.com/questions/25186957/log4j2-securetcpsocketserver-setup">This helped reach that conclusion</a>. This class was in core.net.server which is no longer available.Assuming it is not used anymore and the only similar/closest class, TcpSocketManager.Other links that helped. <a href="https://stackoverflow.com/questions/11825917/log4j-how-does-a-socket-appender-work">How to use SocketAppend?</a></li>
  <li><p>Then i tried this</p>
  
  <pre><code>public static final Logger LOG=LogManager.getLogger(myapp.class.getName());
  
  main(){
  LOG.debug("DEBUG LEVEL");
  }
  </code></pre></li>
  </ol>
  
  <p>and got the following error</p>
  
  <blockquote>
    <p>main ERROR TcpSocketManager (TCP:IPAddress:8111) caught exception 
    and will continue: java.net.SocketTimeoutException: connect timed out</p>
  </blockquote>
  
  <p>I know this work because i made it read to a socket but there was no one listening, but somehow i messed up big time and there was a code change.</p>
  
  <p>I need help how to go ahead. Thank You in advance</p>