Skip to content
Livestream: Custom Authentication in ASP.NET Core - RemoteAuthenticationHandler with Erin and Robert from Active Solution. Register Now!

OIDC Client Logging

OidcClient logs errors, warnings, and diagnostic information using Microsoft.Extensions.Logging.ILogger, the standard .NET logging library.

using Duende.IdentityModel;
using Duende.IdentityModel.OidcClient;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddSingleton(svc =>
{
var loggerFactory = svc.GetRequiredService<ILoggerFactory>();
var options = new OidcClientOptions
{
Authority = "https://demo.duendesoftware.com",
ClientId = "interactive.public",
Scope = "openid profile email offline_access",
RedirectUri = "app://localhost/",
PostLogoutRedirectUri = "app://localhost/",
LoggerFactory = loggerFactory
};
return new OidcClient(options);
});
var app = builder.Build();
var client = app.Services.GetService<OidcClient>();

You can use any logging provider to store your logs however you like, by setting the LoggerFactory property on OidcClientOptions.

For example, you could configure Serilog like this:

var serilog = new LoggerConfiguration()
.MinimumLevel.Verbose()
.Enrich.FromLogContext()
.WriteTo.LiterateConsole(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message}{NewLine}{Exception}{NewLine}")
.CreateLogger();
options.LoggerFactory.AddSerilog(serilog);

The OidcClient logs at the following levels:

  • Trace
  • Debug
  • Information
  • Error

You can set the log level in your appsettings.json by modifying the following snippet.

{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information",
"Duende.IdentityModel.OidcClient": "Error"
}
}
}