-
Notifications
You must be signed in to change notification settings - Fork 856
Aspire DCP injection of LOGGING__CONSOLE__FORMATTERNAME overrides Console LogLevel configuration from appsettings #15913
Description
When Aspire's DCP orchestrator launches a project resource, it injects the environment variable LOGGING__CONSOLE__FORMATTERNAME=simple. This causes the Console provider to ignore its LogLevel section from appsettings.{Environment}.json, falling back to the root LogLevel instead.
Steps to reproduce
- Create an Aspire AppHost with a project resource
- Configure in the project's
appsettings.json(base):
{
"Logging": {
"LogLevel": { "Default": "Trace" },
"Console": {
"LogLevel": { "Default": "Trace" }
}
}
}- Restrict in
appsettings.Development.json:
{
"Logging": {
"Console": {
"LogLevel": {
"Default": "Critical",
"Microsoft.Hosting.Lifetime": "Error"
},
"FormatterName": "simple"
}
}
}- Run the AppHost via
dotnet run - Check Console logs tab in the Aspire dashboard
Expected behavior
Console provider respects "Default": "Critical", only Critical messages appear.
Actual behavior
Console outputs dbug, trce, and info from all namespaces. Diagnostic output confirms builder.Configuration["Logging:Console:LogLevel:Default"] returns "Critical", the config values are correct, but the Console provider ignores them.
Root cause
DCP injects LOGGING__CONSOLE__FORMATTERNAME=simple. This env var creates a partial Logging:Console config section that interferes with the Logging:Console:LogLevel section from appsettings, causing the Console provider to fall back to the root LogLevel (Trace).
File: src/Aspire.Hosting/Dashboard/ConsoleLogsConfigurationExtensions.cs, line 22:
// Enable Simple Console Logger Formatting
context.EnvironmentVariables["LOGGING__CONSOLE__FORMATTERNAME"] = "simple";Called from: src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs, line 435:
builder.ConfigureConsoleLogs();This runs for every project resource added via AddProject(), but only in run mode (not publish mode). It injects two env vars:
DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION=trueLOGGING__CONSOLE__FORMATTERNAME=simple
Suggested fix
- Stop injecting
LOGGING__CONSOLE__FORMATTERNAMElet the app's appsettings control the formatter - Or inject via a mechanism that doesn't interfere with the config section hierarchy
Workaround
From the project side, run the following
Environment.SetEnvironmentVariable("LOGGING__CONSOLE__FORMATTERNAME", null);Environment
- Aspire 13.2.0