Dima Bondarenko
Dima Bondarenko

Reputation: 51

Forbidden when posting events to Seq from Serilog.Sinks.Seq

I have issue with posting logs from C# Console App to Seq. I am using NuGet package Serilog.Sinks.Seq for logging. In the console output I get error message:

Exception while emitting periodic batch from Serilog.Sinks.Seq.SeqSink: Serilog.Debugging.LoggingFailedException: Received failed result Forbidden when posting events to Seq

Seq is configured to accept all logs so it's not clear to me why logging to Seq is forbidden.

Source code of the console app:

using Serilog;
using System;

namespace SeqLogTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration().WriteTo.Seq("http://localhost:5341").CreateLogger();

            Serilog.Debugging.SelfLog.Enable(Console.Error);

            Log.Warning("Hello Seq, it is warning!");

            Log.CloseAndFlush();

            Console.ReadKey();
        }
    }
}

Thanks for any help!

Upvotes: 2

Views: 2930

Answers (2)

Dan Dohotaru
Dan Dohotaru

Reputation: 3089

Have been witnessing a very peculiar problem with seq on windows that was not ingesting any logs, similar to what @dima-bondarenko was reporting.
The error message was slightly different Failed with status code ServiceUnavailable (Service Unavailable)
Nevertheless I'll leave some troubleshooting ideas in here as well, maybe one day someone might benefit from it :)

In our case, serilog was running along with a .net 5 api having seq as yet another sink.
The setup was working just fine out of the box, without any particular configuration on quite a few dev machines except one.
Logs ingestion simply did not work and nothing ended up being logged in seq.

Things to look after

  • enable self log to surface the actual error
Serilog.Debugging.SelfLog.Enable(Console.Error);

Failed with status code ServiceUnavailable (Service Unavailable)

  • push messages via the cli
seqcli log -m Hello

Failed with status code ServiceUnavailable (Service Unavailable)

  • inspect page with curl
curl http://localhost:5341

sounded like the corporate proxy was interfering, though the don't use the proxy for local addresses proxy system setting was enabled

<p>Generated Mon, 19 Apr 2021 12:27:26 GMT by proxy.some.domain.com</p>
<!-- ERR_CONNECT_FAIL -->
  • inspect the environment variables
printenv HTTP_PROXY

bingo, some docker leftovers might have altered the http proxy setting.
removing the environment variable made the seqcli push happy again.

seqcli log -m "Hello again"

but the application was still witnessing Service Unavailable though

  • check firewall inbound rules for port 5341 as there was one rule similar to the bellow snippet
netsh advfirewall firewall add rule name="Seq Open Port 5341" dir=in action=allow protocol=TCP localport=5341

at first sight, removing the firewall inbound rule did not seem to have fixed the Service Unavailable though

  • restart the machine

and guess what, everything is back to normal again

At the end of the day seq is a fantastic product and generally speaking it just works :)
but sometimes the combination of some misconfiguration factors could easily ruin the day :)

Upvotes: 1

Dima Bondarenko
Dima Bondarenko

Reputation: 51

So it turned out that the reason of the problem was incorrectly created Windows firewall rule which was supposed to allow connections on port 5341 but it wasn't working actually. After having deleted the rule, Seq started showing logs just fine.

Upvotes: 2

Related Questions