title: IOException while attempting to communicate with Loggly java.net.SocketException: Socket is closed
body: <p>I am trying to send android logs to Loggly and for that using logback logging. I created a simple project to test the functionality. I got to know that either we need to violate strict mode or create Async task to send logs otherwise it will give you NetworkOnMainThreadException. So I tried StrictMode for now. But after using that now I am getting "java.net.SocketException: Socket is closed" this exception. </p>
  
  <p>I searched a lot and tried few things but no success so far on it. Not sure how to get rid of this issue. Does anybody know how to solve this issue so that I can send android logs to loggly via logback logging which uses slf4j..! Using android-studio and gradle build for it.</p>
  
  <p>Attaching the code snippet and generated error log for reference.
  Thanks! </p>
  
  <p>MainActivity Class:</p>
  
  <pre><code>    import android.os.StrictMode;
      import android.support.v7.app.AppCompatActivity;
      import android.os.Bundle;
      import org.slf4j.Logger;
      import org.slf4j.LoggerFactory;
  
      public class MainActivity extends AppCompatActivity  {
  
      final static Logger logger = LoggerFactory.getLogger(MainActivity.class);
  
          @Override
          protected void onCreate(Bundle savedInstanceState){
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
  
  
          StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                  .permitAll()
                  .build());
  
          logger.info("This is a dummy info message");
          logger.info("This is another dummy info message for testing");
          logger.debug("This is a dummy debug message.");
  
      }
  }
  </code></pre>
  
  <p>logback.xml:</p>
  
  <pre><code>&lt;configuration debug='true'&gt;
  
    &lt;appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"&gt;
      &lt;filter class="ch.qos.logback.classic.filter.LevelFilter"&gt;
        &lt;level&gt;INFO&lt;/level&gt;
        &lt;onMatch&gt;ACCEPT&lt;/onMatch&gt;
        &lt;onMismatch&gt;DENY&lt;/onMismatch&gt;
      &lt;/filter&gt;
      &lt;encoder&gt;
        &lt;pattern&gt;%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n&lt;/pattern&gt;
      &lt;/encoder&gt;
    &lt;/appender&gt;
  
    &lt;!-- Create a file appender for a log in the application's data directory --&gt;
    &lt;appender name="file" class="ch.qos.logback.core.FileAppender"&gt;
      &lt;file&gt;/data/data/com.android.myapplication/files/log/logbackLogs.log&lt;/file&gt;
      &lt;encoder&gt;
        &lt;pattern&gt;%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n&lt;/pattern&gt;
      &lt;/encoder&gt;
    &lt;/appender&gt;
  
    &lt;appender name="LOGGLY" class="ch.qos.logback.ext.loggly.LogglyAppender"&gt;
      &lt;endpointUrl&gt;https://logs-01.loggly.com/inputs/TOKEN/tag/logbacklogglytest&lt;/endpointUrl&gt;
      &lt;pattern&gt;%d{"ISO8601", UTC}  %p %t %c{0}.%M - %m%n&lt;/pattern&gt;
    &lt;/appender&gt;
  
    &lt;!-- Write INFO (and higher-level) messages to the log file --&gt;
    &lt;root level="DEBUG"&gt;
      &lt;appender-ref ref="file" /&gt;
      &lt;appender-ref ref="STDOUT" /&gt;
      &lt;appender-ref ref="LOGGLY" /&gt;
    &lt;/root&gt;
  
  &lt;/configuration&gt;
  </code></pre>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code> &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;
  </code></pre>
  
  <p>Gradle build file:</p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 23
      buildToolsVersion "23.0.2"
  
      defaultConfig {
          applicationId "com.android.myapplication"
          minSdkVersion 18
          targetSdkVersion 23
          versionCode 1
          versionName "1.0"
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
  }
  
  dependencies {
      compile fileTree(include: ['*.jar'], dir: 'libs')
      testCompile 'junit:junit:4.12'
      compile 'com.android.support:appcompat-v7:23.1.1'
      compile project(':logback-android-1.1.1-4')
      compile project(':slf4j-api-1.7.6')
      compile project(':logback-ext-loggly-0.1.4')
  }
  </code></pre>