2

I have aspnetcore2 api that is using IdentityServer4.AccessTokenValidation and Microsoft.AspNetCore.Authentication.JwtBearer packes to handle access token authentication.

I've setup Serilog logging in my application with the following config:

Log.Logger = new LoggerConfiguration()
    .Enrich.FromLogContext()
    .MinimumLevel.Information()
    .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
    .MinimumLevel.Override("System", LogEventLevel.Warning)
    .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Warning)
    .WriteTo.Logger(l => l.MinimumLevel.Verbose().WriteTo.Console())
    .WriteTo.Logger(l => l.MinimumLevel.Information().WriteTo.File("logs/logfile.log",
        rollingInterval: RollingInterval.Day, retainedFileCountLimit: 10))
    .CreateLogger();

I was able to Override log levels for System and Microsoft log sources.

However I still receive the following log entry in my log file:

2018-05-23 20:30:27.228 -04:00 [INF] AuthenticationScheme: Bearer was successfully authenticated.

I can't seem to figureout the log source for Microsoft.AspNetCore.Authentication.JwtBearer so I can filter them out like I did System and Microsoft.

Eugene S.
  • 3,256
  • 1
  • 25
  • 36
  • Yes, I was able to trace the logger. Since I'm using `IdentityServer4.AccessTokenValidation` they implement their own `Microsoft.AspNetCore.Authentication.AuthenticationHandler`. So the log source ended up being `IdentityServer4.AccessTokenValidation.IdentityServerAuthenticationHandler` – Eugene S. May 29 '18 at 21:23
  • Simply adding `.MinimumLevel.Override("IdentityServer4", LogEventLevel.Warning)` also works – Eugene S. May 29 '18 at 21:28
  • Are log sources linked to the assembly? I'm running into this and trying to filter out those pesky MSFT logs – rdelgado-incinc Aug 03 '20 at 23:25

0 Answers0