SumoLogic / sumologic-net-appenders

Several appenders for .NET developers to use that send logs straight to SumoLogic.
Apache License 2.0
23 stars 39 forks source link

log4net appender is getting a WebException using collector endpoint #95

Open kylegalbraith opened 4 years ago

kylegalbraith commented 4 years ago

I am running a .NET 4.5 console app that I am trying to ship up the logs to my HTTP collector in my Sumo Logic account. Below is my XML configuration in App.config.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <log4net>
    <appender name="SumoLogicAppender" type="SumoLogic.Logging.Log4Net.SumoLogicAppender, SumoLogic.Logging.Log4Net">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="{&quot;EntryDate&quot;:&quot;%date{ddd MMM dd HH:mm:ss zzz yyyy}&quot;,            &quot;Level&quot;:&quot;%level&quot;,            &quot;Logger&quot;:&quot;%logger&quot;,            &quot;Message&quot;:&quot;%message&quot;}            %newline" />
      </layout>
      <Url value="https://endpoint1.collection.us2.sumologic.com/receiver/v1/http/==my_token==" />
      <ConnectionTimeout value="30000" />
      <!-- in milliseconds -->
      <SourceName value="RecordResults" />
    </appender>
    <root>
      <level value="ALL" />
      <priority value="ALL" />
      <appender-ref ref="SumoLogicAppender" />
    </root>
  </log4net>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <appSettings>
    <add key="log4net.Internal.Debug" value="true"/>
  </appSettings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.8.0" newVersion="2.0.8.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

But in my Program.cs I am getting an exception as soon as the logger goes to ship up a log message.

Here is the sample code:

class Program
    {
        private static readonly ILog log = LogManager.GetLogger("RecordResults");
        static void Main(string[] args)
        {
            CustomClass classApi = new CustomClass(log);
            while (true)
            {
                log.Info("Begin record results pass...");
                try
                {
                    classApi.StartWorker();
                }
                catch(Exception e)
                {
                    log.Error(e);
                }
                log.Info("Finished record results pass...");
            }
        }
    }

Here is the exception:

log4net:ERROR [SumoLogicAppender] ErrorCode: GenericFailure. Failed in DoAppend
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
   at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
   --- End of inner exception stack trace ---
   at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
   at System.Net.PooledStream.EndWrite(IAsyncResult asyncResult)
   at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
   at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)
   --- End of inner exception stack trace ---
   at SumoLogic.Logging.Common.Sender.SumoLogicMessageSender.TrySend(String body, String name)
   at SumoLogic.Logging.Log4Net.SumoLogicAppender.Append(LoggingEvent loggingEvent)
   at log4net.Appender.AppenderSkeleton.DoAppend(LoggingEvent loggingEvent)

I am on the latest version of the Nuget package and log4net. I am using the collection endpoint for my configured collector. I'm at a bit of a loss on what the issue is here.

insane4sure commented 4 years ago

@kylegalbraith did you make progress on this? I'm also experiencing this issue, exactly as described above. I'm a noob to sumologic, so I assume my endpoint url is invalid.

lei-sumo commented 4 years ago

Can you check if you are on tls 1.2 or later? This might be relevant https://stackoverflow.com/questions/30516001/an-existing-connection-was-forcibly-closed-by-the-remote-host-when-connecting