borisermakof / serilog-sinks-fluentd

A Sink that writes logs into Fluentd
Apache License 2.0
20 stars 30 forks source link

Unhandled Exception: System.Net.Sockets.SocketException: Invalid argument #2

Open andy-g opened 6 years ago

andy-g commented 6 years ago

I've just started looking at fluentd & was keen to try spin up a dotnet core sample that logs to fluentd.

I've setup a Elastic Search, Kibana & Fluentd stack on docker locally (https://docs.fluentd.org/v0.12/articles/docker-logging-efk-compose) and everything is working fine (forwarding docker logs from an apache container through fluentd into kibana & logstash).

I then installed Serilog.AspNetCore, Serilog.Sinks.Console & Serilog.Sinks.Fluentd.

Console logging works fine, but as soon as I try to log to Fluentd I get the following error:

Unhandled Exception: System.Net.Sockets.SocketException: Invalid argument
   at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
   at System.Net.Sockets.Socket.SetLingerOption(LingerOption lref)
   at System.Net.Sockets.Socket.SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, Object optionValue)
   at Serilog.Sinks.Fluentd.FluentdSink..ctor(FluentdSinkOptions options)
   at Serilog.LoggerConfigurationFluentdExtensions.Fluentd(LoggerSinkConfiguration loggerSinkConfiguration, FluentdSinkOptions option)
   at app.Program.Main(String[] args) in /Users/andy/Development/experiments/dotnet/TodoApi/Program.cs:line 19

This is what my program.cs file looks like:

using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Serilog;
using Serilog.Events;
using Serilog.Sinks.Fluentd;

namespace app
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                .Enrich.FromLogContext()
                .WriteTo.Fluentd(new FluentdSinkOptions("0.0.0.0",24224))
                .WriteTo.Console()
                .CreateLogger();

            Log.Information("Starting web host");

            BuildWebHost(args).Run();
        }

        public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseSerilog()
                .UseStartup<Startup>()
                .Build();
    }
}

I've tried with our without the FluentdSinkOptions, but I consistently get the error.

I'm relatively new to dotnet core, and totally new to fluentd, so I could well be missing something, but couldn't find any usage examples for the fluentd sink, and would be hugely appreciative if you could help me out.

I'm on a mac, running dotnet core 2.0, and nuget installed and referenced Serilog.Sinks.Fluentd Version 0.2.0.

Thanks so much

Alessar commented 6 years ago

Hi @andy-g FluentdSinkOptions with 0.0.0.0 very confusing me. Can you try to put real IP address or at least localhost ? I can assume that pattern 0.0.0.0 works only with listen sockets, but not with sockets which will use to send data.

d-arkhipenko commented 5 years ago

Hi @andy-g You need to set FluentdSinkOptions.LingerTime less than 327 seconds

image