microsoft / microsoft/aspire

Aspire DCP injection of `LOGGING__CONSOLE__FORMATTERNAME` overrides Console `LogLevel` configuration from appsettings

Open
#15,913 0 comments 0 reactions 0 assignees View on GitHub
area-app-model
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

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
1. Create an Aspire AppHost with a project resource
2. Configure in the project's `appsettings.json` (base):

```json
{
"Logging": {
"LogLevel": { "Default": "Trace" },
"Console": {
"LogLevel": { "Default": "Trace" }
}
}
}
```

3. Restrict in `appsettings.Development.json`:
```json
{
"Logging": {
"Console": {
"LogLevel": {
"Default": "Critical",
"Microsoft.Hosting.Lifetime": "Error"
},
"FormatterName": "simple"
}
}
}
```

4. Run the AppHost via `dotnet run`
5. 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](https://github.com/microsoft/aspire/blob/main/src/Aspire.Hosting/Dashboard/ConsoleLogsConfigurationExtensions.cs#L22), line 22:

```csharp
// Enable Simple Console Logger Formatting
context.EnvironmentVariables["LOGGING__CONSOLE__FORMATTERNAME"] = "simple";
```

Called from: [src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs](https://github.com/dotnet/aspire/blob/main/src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs#L435), line 435:

```csharp
builder.ConfigureConsoleLogs();
```

This runs for every project resource added via AddProject(), but only in run mode (not publish mode). It injects two env vars:

1. `DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION=true`
2. `LOGGING__CONSOLE__FORMATTERNAME=simple`

## Suggested fix
1. Stop injecting `LOGGING__CONSOLE__FORMATTERNAME` let the app's appsettings control the formatter
2. Or inject via a mechanism that doesn't interfere with the config section hierarchy

## Workaround

From the project side, run the following

```csharp
Environment.SetEnvironmentVariable("LOGGING__CONSOLE__FORMATTERNAME", null);
```

## Environment

- Aspire 13.2.0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.