Why is asp.net logging twice, once with a default setting and once with my serilog settings?

71 views Asked by At

I am using .net 8 and Serilog.AspNetCore 8.0.1

This is my config:

 builder.Logging.ClearProviders();
  builder.Host.UseSerilog((context, provider, configuration) => configuration
    .ReadFrom.Configuration(context.Configuration)
    .ReadFrom.Services(provider)
    .Enrich.FromLogContext()
    .Enrich.WithThreadId()
    .Enrich.WithThreadName()
    .WriteTo.Console(new CompactJsonFormatter()));

  app.UseSerilogRequestLogging();
{
  "Serilog": {
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Microsoft": "Warning",
        "System": "Warning"
      }
    },
    "WriteTo": [
      {
        "Name": "Console"
      }
    ]
  },
  "Logging": {
    "LogLevel": {
      "Default": "None"
    }
  }
}

I get this output

[10:00:44 INF] Registered 3 endpoints in 372 milliseconds.
{"@t":"2024-02-09T09:00:44.2162343Z","@mt":"Registered {@total} endpoints in {@time} milliseconds.","total":3,"time":"372","SourceContext":"FastEndpoints.StartupTimer","ThreadId":1}
[10:00:44 INF] No validators found in the system!
{"@t":"2024-02-09T09:00:44.3580656Z","@mt":"No validators found in the system!","SourceContext":"FastEndpoints.Swagger.ValidationSchemaProcessor","ThreadId":1}
[10:00:45 WRN] Failed to determine the https port for redirect.
{"@t":"2024-02-09T09:00:45.0580324Z","@mt":"Failed to determine the https port for redirect.","@l":"Warning","@tr":"e268d09fb1a82c6b14ff4009b2c78fb2","@sp":"812993de2d9a8a49","EventId":{"Id":3,"Name":"FailedToDeterminePort"},"SourceContext":"Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware","RequestId":"0HN199MCOC79T:00000001","RequestPath":"//swagger","ConnectionId":"0HN199MCOC79T","ThreadId":9,"ThreadName":".NET TP Worker"}
[10:00:45 INF] HTTP GET //swagger responded 302 in 15.6650 ms
{"@t":"2024-02-09T09:00:45.0698076Z","@mt":"HTTP {RequestMethod} {RequestPath} responded {StatusCode} in {Elapsed:0.0000} ms","@r":["15.6650"],"@tr":"e268d09fb1a82c6b14ff4009b2c78fb2","@sp":"812993de2d9a8a49","RequestMethod":"GET","RequestPath":"//swagger","StatusCode":302,"Elapsed":15.665,"SourceContext":"Serilog.AspNetCore.RequestLoggingMiddleware","RequestId":"0HN199MCOC79T:00000001","ConnectionId":"0HN199MCOC79T","ThreadId":9,"ThreadName":".NET TP Worker"}

Why is it logging the non json formatted messages and how can I turn that off?

0

There are 0 answers