question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Serilog Seq unable to send logs to http://localhost

See original GitHub issue

I have the most trivial test app to experiment with Serilog Seq:

static void Main(string[] args)
{
    try
    {
        Serilog.Debugging.SelfLog.Enable(Console.Error);

        var logger = new LoggerConfiguration()
            .WriteTo.Seq("http://localhost:5341")
            .CreateLogger();

        logger.Information("hello world");

        Thread.Sleep(TimeSpan.FromSeconds(100));
    }
    finally
    {
        Log.CloseAndFlush();
    }
}

The logs are pushed to a local docker instance running Seq, setup using instructions from https://docs.datalust.co/docs/getting-started-with-docker.

However, I continue to get the following error when the Seq serverUrl is http://localhost:5341. I don’t get this error when the URL is changed to http://127.0.0.1:5341. Is anyone able to help explain why that is?

FYI: I am able to POST a message to the Seq container using the following curl command: curl -XPOST "http://localhost:5341/api/events/raw?clef" -d "{'@t':'2018-06-07T03:44:57.8532799Z','@mt':'Hello, {User}','User':'alice'}", which makes me think this isn’t a local network issue.

2021-11-16T01:55:29.5226349Z Exception while emitting periodic batch from Serilog.Sinks.Seq.SeqSink: System.Net.Http.HttpRequestException: An error occurred while sending the request. —> 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 (10054): An existing connection was forcibly closed by the remote host. — End of inner exception stack trace — at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken) at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.GetResult(Int16 token) at System.Net.Http.HttpConnection.FillAsync(Boolean async) at System.Net.Http.HttpConnection.ReadNextResponseHeaderLineAsync(Boolean async, Boolean foldedHeadersAllowed) at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) — End of inner exception stack trace — at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpClient.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken) at Serilog.Sinks.Seq.SeqSink.EmitBatchAsync(IEnumerable`1 events) at Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.OnTick()

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
marner2commented, Mar 23, 2022

We are running into this exact same error message, but it is having the effect of adding logs every 15 seconds to our localhost seq server. This issue does not arise if the server is not localhost.

image

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 (10054): An existing connection was forcibly closed by the remote host.
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.CreateException(SocketError error, Boolean forAsyncThrow)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ReceiveAsync(Socket socket, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.ReceiveAsync(Memory`1 buffer, SocketFlags socketFlags, Boolean fromNetworkStream, CancellationToken cancellationToken)
   at System.Net.Sockets.NetworkStream.ReadAsync(Memory`1 buffer, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnection.<CheckUsabilityOnScavenge>g__ReadAheadWithZeroByteReadAsync|44_0()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at System.Net.Http.HttpConnection.<CheckUsabilityOnScavenge>g__ReadAheadWithZeroByteReadAsync|44_0()
   at System.Net.Http.HttpConnection.CheckUsabilityOnScavenge()
   at System.Net.Http.HttpConnectionPool.<CleanCacheAndDisposeIfUnused>g__IsUsableConnection|115_2(HttpConnectionBase connection, Int64 nowTicks, TimeSpan pooledConnectionLifetime, TimeSpan pooledConnectionIdleTimeout)
   at System.Net.Http.HttpConnectionPool.<CleanCacheAndDisposeIfUnused>g__ScavengeConnectionList|115_1[T](List`1 list, List`1& toDispose, Int64 nowTicks, TimeSpan pooledConnectionLifetime, TimeSpan pooledConnectionIdleTimeout)
   at System.Net.Http.HttpConnectionPool.CleanCacheAndDisposeIfUnused()
   at System.Net.Http.HttpConnectionPoolManager.RemoveStalePools()
   at System.Net.Http.HttpConnectionPoolManager.<>c.<.ctor>b__11_0(Object s)
   at System.Threading.TimerQueueTimer.Fire(Boolean isThreadPool)
   at System.Threading.TimerQueue.FireNextTimers()
   at System.Threading.UnmanagedThreadPoolWorkItem.ExecuteUnmanagedThreadPoolWorkItem(IntPtr callback, IntPtr state)
   at System.Threading.UnmanagedThreadPoolWorkItem.ExecuteUnmanagedThreadPoolWorkItem(IntPtr callback, IntPtr state)
   at System.Threading.UnmanagedThreadPoolWorkItem.System.Threading.IThreadPoolWorkItem.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
   at System.Threading.Thread.StartCallback()
--- End of stack trace from previous location ---

   --- End of inner exception stack trace ---
   at System.Net.Http.HttpConnection.<CheckUsabilityOnScavenge>g__ReadAheadWithZeroByteReadAsync|44_0()

Configuration:

{
  "Serilog": {
    "MinimumLevel": {
      "Default": "Verbose"
    },
    "WriteTo": [
      {
        "Name": "Seq",
        "Args": {
          "restrictedToMinimumLevel": "Verbose",
          "serverUrl": "http://localhost:5341",
          "retainedInvalidPayloadsLimitBytes": 8000000
        }
      }
    ]
  }
}
1reaction
colin-simcommented, Nov 16, 2021

In the docs you’ve linked, the example sets Log.Logger - hence CloseAndFlush() is needed in that case. OK. Do you know if there is a way to flush all Serilog logs before shutdown?

Do the events actually make it into Seq? No

Are there any errors shown in the Seq Ingestion Log? (Data > Ingestion, or Settings > Diagnostics > Ingestion Log, should show it) No - event definitely hasn’t made it Seq.

Just ran the same code here, on .NET 6 + Windows 10 with Seq running in the latest Docker desktop - no error message I’m not surprised. So for me, the same above works when I use 127.0.0.1 as the host; however, get the error when the host is localhost.

I don’t get the same error when using utilities like curl. The error is not likely specific to Serilog Seq library but potentially be with C# (or it’s underlying libraries). I just don’t understand why this inconsistency exists and was hoping someone in this community would know.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Serilog and seq when no server available
What is the expected behavior when an application that uses Serilog and Seq can't find a server to send the logs to?
Read more >
Why is Serilog not writing my logs into Seq? (Console app)
Now this works for both console and Seq. It will send any remaining messages to Seq before normally closing the application.
Read more >
C# Logging with Serilog and Seq - YouTube
Serilog is an easy to configure and easy to use logging system that you can ... structured logging by hooking up a visual...
Read more >
Logging into Elasticsearch using Serilog and viewing logs in ...
Your browser can't play this video. Learn more.
Read more >
Couldnot log to remote server! - Seq Documentation - Datalust
I use Serilog. I can see my local text logs but couldnot see these logs at Seq. I located seq at a remote...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found