Skip to content

Commit 1746394

Browse files
authored
Merge pull request #985 from DuendeSoftware/mb/logging
Useful log namespaces and instructions on how to override the default log levels #723
2 parents 0748008 + d4532ef commit 1746394

5 files changed

Lines changed: 197 additions & 167 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: "Logging"
3+
description: "Documentation for logging configuration and usage in Duende Access Token Management, including log levels and Serilog setup"
4+
date: 2026-01-19
5+
sidebar:
6+
order: 50
7+
---
8+
9+
Duende Access Token Management uses the standard logging facilities provided by ASP.NET Core. You generally do not need to perform any extra configuration, as it will use the logging provider you have already configured for your application.
10+
11+
For general information on how to configure logging, setting up Serilog, and understanding log levels in Duende products, see our [Logging Fundamentals](/general/logging.md) guide.
12+
13+
The Microsoft [documentation](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging) has a good introduction and description of the built-in logging providers.
14+
15+
## Log Levels
16+
17+
You can control the log output for Duende Access Token Management specifically by configuring the `Duende.AccessTokenManagement` namespace in your logging configuration.
18+
For example, to enable debug logging for Access Token Management while keeping other logs at a higher level, you can modify your `appsettings.json`:
19+
20+
```json
21+
// appsettings.json
22+
{
23+
"Logging": {
24+
"LogLevel": {
25+
"Default": "Information",
26+
"Duende.AccessTokenManagement": "Debug"
27+
}
28+
}
29+
}
30+
```

src/content/docs/bff/diagnostics/index.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,28 @@ provided by ASP.NET Core, so you don't need to do any extra configuration to ben
1414
including support for multiple logging providers. See the Microsoft [documentation](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging) for a good introduction on logging.
1515

1616
BFF follows the standard logging levels defined by the .NET logging framework, and uses the Microsoft guidelines for
17-
when certain log levels are used, similar to [how Duende IdentityServer uses log levels](/identityserver/diagnostics/logging.md).
17+
when certain log levels are used.
18+
19+
For general information on how to configure logging in Duende products, see our [Logging Fundamentals](/general/logging.md) guide.
20+
21+
### Configuration
1822

1923
Logs are typically written under the `Duende.Bff` category, with more concrete categories for specific components.
2024

25+
To get detailed logs from the BFF middleware with the `Microsoft.Extensions.Logging` framework, you can configure your `appsettings.json` to enable `Debug` level logs for the `Duende.Bff` namespace:
26+
27+
```json
28+
// appsettings.json
29+
{
30+
"Logging": {
31+
"LogLevel": {
32+
"Default": "Information",
33+
"Duende.Bff": "Debug"
34+
}
35+
}
36+
}
37+
```
38+
2139
:::note[Multiple frontends]
2240
When using [multiple frontends and the `FrontendSelectionMiddleware`](/bff/architecture/multi-frontend.md),
2341
log messages are written in a log scope that contains a `frontend` property with the name of the frontend for which the
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
---
2+
title: "Logging Fundamentals"
3+
description: "General guidance on configuring logging for Duende Software products using Microsoft.Extensions.Logging and Serilog."
4+
date: 2026-01-19
5+
sidebar:
6+
order: 10
7+
---
8+
9+
All Duende Software products (IdentityServer, Backend for Frontend (BFF), Access Token Management, etc.) use the standard logging facilities provided by ASP.NET Core (`Microsoft.Extensions.Logging`).
10+
This means they integrate seamlessly with whatever logging provider you choose for your application.
11+
12+
This guide provides general instructions for setting up logging that apply to all our products.
13+
14+
## Log Levels
15+
16+
We adhere to the standard Microsoft guidelines for log levels. Understanding these levels helps you configure the appropriate verbosity for your environment.
17+
18+
* **`Trace`**
19+
* **Usage:** Extremely detailed information for troubleshooting complex issues.
20+
* **Production:** **Do not enable** in production unless specifically instructed for diagnostics. May contain sensitive data (e.g., token hashes, PII).
21+
* **`Debug`**
22+
* **Usage:** Internal flow details, useful for understanding _why_ a decision was made (e.g., policy evaluation, token validation steps).
23+
* **Production:** Generally disabled in production, but safe to enable temporarily for deeper investigation.
24+
* **`Information`**
25+
* **Usage:** High-level events tracking the general flow (e.g., "Request started", "Token issued").
26+
* **Production:** Often the default level for production.
27+
* **`Warning`**
28+
* **Usage:** Unexpected events that didn't stop the application but might require investigation (e.g., "Invalid client configuration detected").
29+
* **`Error`**
30+
* **Usage:** Exceptions and errors that cannot be handled gracefully.
31+
* **`Critical`**
32+
* **Usage:** Failures that require immediate attention (e.g., "Signing key not found").
33+
34+
## Setup for Microsoft.Extensions.Logging
35+
36+
This is the default logging provider for ASP.NET Core. If you haven't configured a third-party logger, this is what you are using.
37+
38+
You can configure log levels in your `appsettings.json` file. To get detailed logs from Duende products, you often want to set the `Duende` namespace (or specific sub-namespaces) to `Debug`.
39+
40+
```json
41+
// appsettings.json
42+
{
43+
"Logging": {
44+
"LogLevel": {
45+
"Default": "Information",
46+
"Microsoft": "Warning",
47+
"Microsoft.Hosting.Lifetime": "Information",
48+
// Enable Debug logs for all Duende products
49+
"Duende": "Debug"
50+
}
51+
}
52+
}
53+
```
54+
55+
## Setup for Serilog
56+
57+
[Serilog](https://serilog.net) is a popular structured logging library for .NET. We highly recommend it for its flexibility and rich sink ecosystem (Console, File, Seq, Elasticsearch, etc.).
58+
59+
### 1. Installation
60+
61+
Install the necessary packages:
62+
63+
```bash
64+
dotnet add package Serilog.AspNetCore
65+
```
66+
67+
### 2. Configuration In `Program.cs`
68+
69+
Configure Serilog early in your application startup to capture all logs, including startup errors.
70+
71+
```csharp
72+
// Program.cs
73+
using Serilog;
74+
75+
var builder = WebApplication.CreateBuilder(args);
76+
77+
// Configure Serilog
78+
builder.Host.UseSerilog((ctx, lc) => lc
79+
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}")
80+
.Enrich.FromLogContext()
81+
.ReadFrom.Configuration(ctx.Configuration));
82+
83+
var app = builder.Build();
84+
85+
app.UseSerilogRequestLogging(); // Optional: cleaner HTTP request logging
86+
87+
// ... rest of your pipeline
88+
```
89+
90+
### 3. Configuration In `appsettings.json`
91+
92+
You can then control log levels via `appsettings.json`. This approach allows you to change log levels without recompiling your code.
93+
94+
```json
95+
{
96+
"Serilog": {
97+
"MinimumLevel": {
98+
"Default": "Information",
99+
"Override": {
100+
"Microsoft": "Warning",
101+
"Microsoft.Hosting.Lifetime": "Information",
102+
"System": "Warning",
103+
// Enable detailed logging for Duende products
104+
"Duende": "Debug"
105+
}
106+
}
107+
}
108+
}
109+
```
110+
111+
## Troubleshooting Specific Products
112+
113+
If you are debugging a specific component, you can target its namespace to reduce noise.
114+
115+
| Product | Namespace |
116+
|-----------------------------|--------------------------------|
117+
| **IdentityServer** | `Duende.IdentityServer` |
118+
| **BFF** | `Duende.Bff` |
119+
| **Access Token Management** | `Duende.AccessTokenManagement` |
120+
121+
Example `appsettings.json` for debugging only BFF interactions:
122+
123+
```json
124+
"Duende.Bff": "Debug",
125+
"Duende.IdentityServer": "Information"
126+
```

src/content/docs/identitymodel-oidcclient/logging.md

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ redirect_from:
1111
`OidcClient` logs errors, warnings, and diagnostic information using
1212
`Microsoft.Extensions.Logging.ILogger`, the standard .NET logging library.
1313

14-
```csharp
14+
You can use any logging provider to store your logs however you like,
15+
by setting the `LoggerFactory` property on `OidcClientOptions`:
16+
17+
```csharp {9,17}
18+
// Program.cs
1519
using Duende.IdentityModel;
1620
using Duende.IdentityModel.OidcClient;
1721

@@ -36,20 +40,9 @@ var app = builder.Build();
3640
var client = app.Services.GetService<OidcClient>();
3741
```
3842

39-
You can use any logging provider to store your logs however you like, by setting the `LoggerFactory` property on `OidcClientOptions`.
40-
41-
For example, you could configure
42-
[Serilog](https://github.com/serilog/serilog-extensions-hosting) like this:
43+
Using this approach, you can use other logging frameworks, like [Serilog](https://github.com/serilog/serilog-extensions-hosting) for example.
4344

44-
```csharp
45-
var serilog = new LoggerConfiguration()
46-
.MinimumLevel.Verbose()
47-
.Enrich.FromLogContext()
48-
.WriteTo.LiterateConsole(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message}{NewLine}{Exception}{NewLine}")
49-
.CreateLogger();
50-
51-
options.LoggerFactory.AddSerilog(serilog);
52-
```
45+
For general information on how to configure logging in .NET applications, see our [Logging Fundamentals](/general/logging.md) guide.
5346

5447
## Log Levels
5548

@@ -63,6 +56,7 @@ The `OidcClient` logs at the following levels:
6356
You can set the log level in your `appsettings.json` by modifying the following snippet.
6457

6558
```json
59+
// appsettings.json
6660
{
6761
"Logging": {
6862
"LogLevel": {

0 commit comments

Comments
 (0)