Skip to content

Aspire DCP injection of LOGGING__CONSOLE__FORMATTERNAME overrides Console LogLevel configuration from appsettings #15913

@cilerler

Description

@cilerler

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):
{
  "Logging": {
    "LogLevel": { "Default": "Trace" },
    "Console": {
      "LogLevel": { "Default": "Trace" }
    }
  }
}
  1. Restrict in appsettings.Development.json:
{
  "Logging": {
    "Console": {
      "LogLevel": {
        "Default": "Critical",
        "Microsoft.Hosting.Lifetime": "Error"
      },
      "FormatterName": "simple"
    }
  }
}
  1. Run the AppHost via dotnet run
  2. 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:

  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

Environment.SetEnvironmentVariable("LOGGING__CONSOLE__FORMATTERNAME", null);

Environment

  • Aspire 13.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-app-modelIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions