microsoft/aspire · error · ArgumentOutOfRangeException

Unsupported log level.

Error message

Unsupported log level.

What it means

LoggingExports.ParseLogLevel maps a level string to Microsoft.Extensions.Logging.LogLevel and throws ArgumentOutOfRangeException when the string matches no known level name and throwOnUnknown is true. Supported names are trace, debug, information/info, warning/warn, error, and critical.

Solutions

  1. Use one of the supported level strings: trace, debug, information, info, warning, warn, error, critical.
  2. Normalize nonstandard synonyms before calling (e.g., fatal -> critical, verbose -> debug).
  3. Trim the string if it may contain whitespace, or pass throwOnUnknown: false to fall back to Information instead of throwing.

Example fix

// before
Log("verbose", "message");
// after
Log("debug", "message");
Defensive patterns

Strategy: validation

Validate before calling

var allowed = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
    { "trace", "debug", "information", "info", "warning", "warn", "error", "critical" };
if (!allowed.Contains(level))
{
    level = level switch { "verbose" => "debug", "fatal" => "critical", _ => "information" };
}

Type guard

bool IsKnownLogLevel(string s) => s.Trim().ToLowerInvariant() is "trace" or "debug" or "information" or "info" or "warning" or "warn" or "error" or "critical";

Try / catch

try
{
    Log(level, message);
}
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "level")
{
    Log("information", message); // safe fallback
}

Prevention

When it happens

Trigger: Calling the Log ATS export with a level string like "verbose", "fatal", "critical-fatal", "WARN ", or any typo, while throwOnUnknown is enabled (as done by PipelineExports.ParseLogLevel).

Common situations: Level names taken from user scripts or config written in another library's vocabulary (e.g., "verbose", "fatal" from other logging frameworks); trailing whitespace or wrong casing is handled by the parser's ToLowerInvariant but exotic synonyms are not.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/4537ff4300e8709b. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting/Ats/LoggingExports.cs:131

    [AspireExport]
    public static void CompleteLogByName(this ResourceLoggerService loggerService, string resourceName)
    {
        loggerService.Complete(resourceName);
    }

    internal static LogLevel ParseLogLevel(string level, bool throwOnUnknown = false)
    {
        ArgumentNullException.ThrowIfNull(level);

        return level.ToLowerInvariant() switch
        {
            "trace" => LogLevel.Trace,
            "debug" => LogLevel.Debug,
            "information" or "info" => LogLevel.Information,
            "warning" or "warn" => LogLevel.Warning,
            "error" => LogLevel.Error,
            "critical" => LogLevel.Critical,
            _ when throwOnUnknown => throw new ArgumentOutOfRangeException(nameof(level), level, "Unsupported log level."),
            _ => LogLevel.Information
        };
    }
}

View on GitHub (pinned to 25830f84bd)