serilog-contrib / Serilog.Sinks.Logz.Io

Apache License 2.0
15 stars 11 forks source link

restrictedToMinimumLevel not respected #8

Closed mehtadone closed 5 years ago

mehtadone commented 5 years ago

Hi,

I maybe doing something wrong, but I'm using the following setup but debug logs still get sent to Logz.io

  "Serilog": {
    "Using": [
      "Serilog.Sinks.RollingFile"
    ],
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Microsoft": "Information",
        "System": "Warning"
      }
    },
    "WriteTo": {
      "0": {
        "Name": "LogzIo",
        "Args": {
          "restrictedToMinimumLevel": "Information",
          "authToken": "",
          "type": "typename"
        }
      },
    "Enrich": [
      "FromLogContext"
    ]
  },

and the setup of the logger is like so:

Log.Logger = new LoggerConfiguration()
            .ReadFrom.Configuration(configuration)
            .WriteTo.RollingFile(Directory.GetCurrentDirectory() + "/logs/log.log")
            .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                        .CreateLogger();
mantasaudickas commented 5 years ago

Is this a console application? Which library version are you using?

mehtadone commented 5 years ago

It's a asp.net core application on dotnet 2.2. The library versions are below ```"Serilog.AspNetCore" Version="2.1.1" />

<PackageReference Include="Serilog.Settings.Configuration" Version="3.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.Logz.Io" Version="2.2.0" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" /```
mantasaudickas commented 5 years ago

I have published a new package version 2.2.1 with a fix. Just another note, it looks like you are doing your logger configuration wrong way. Correct one would be user Serilog.AspNetCore package and configure your logger using extension method:

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseSerilog((context, configuration) => configuration.ReadFrom.Configuration(context.Configuration), true)
        .UseStartup<Startup>();

I also added example project with it: https://github.com/mantasaudickas/serilog-sinks-logz-io/blob/master/tests/Serilog.Sinks.Logz.Io.AspNetCoreApi/Program.cs#L15 and usage: https://github.com/mantasaudickas/serilog-sinks-logz-io/blob/master/tests/Serilog.Sinks.Logz.Io.AspNetCoreApi/Startup.cs#L38

Thank you for reporting the issue.

mehtadone commented 5 years ago

Perfect. Thank you for the quick fix. Appreciated.

I have also changed the way I'm setting up my logger, but out of curiosity, what are the benefits of using the extension method vs setting Log.Logger?

mantasaudickas commented 5 years ago

Extension methods does more than just sets Log.Logger, but also registers and enables Serilog LoggerFactory.