dotnet/aspnetcore · error · Error

Unknown log level: ${name}

Error message

Unknown log level: ${name}

What it means

Thrown at HubConnectionBuilder.ts:38 by parseLogLevel when a string passed to `configureLogging` does not match any key in LogLevelNameMapping (case-insensitive). Valid strings are trace, debug, info/information, warn/warning, error, critical, none.

Source

Thrown at src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts:38

    debug: LogLevel.Debug,
    info: LogLevel.Information,
    information: LogLevel.Information,
    warn: LogLevel.Warning,
    warning: LogLevel.Warning,
    error: LogLevel.Error,
    critical: LogLevel.Critical,
    none: LogLevel.None,
};

function parseLogLevel(name: string): LogLevel {
    // Case-insensitive matching via lower-casing
    // Yes, I know case-folding is a complicated problem in Unicode, but we only support
    // the ASCII strings defined in LogLevelNameMapping anyway, so it's fine -anurse.
    const mapping = LogLevelNameMapping[name.toLowerCase()];
    if (typeof mapping !== "undefined") {
        return mapping;
    } else {
        throw new Error(`Unknown log level: ${name}`);
    }
}

/** A builder for configuring {@link @microsoft/signalr.HubConnection} instances. */
export class HubConnectionBuilder {
    private _serverTimeoutInMilliseconds?: number;
    private _keepAliveIntervalInMilliseconds ?: number;

    /** @internal */
    public protocol?: IHubProtocol;
    /** @internal */
    public httpConnectionOptions?: IHttpConnectionOptions;
    /** @internal */
    public url?: string;
    /** @internal */
    public logger?: ILogger;

    /** If defined, this indicates the client should automatically attempt to reconnect if the connection is lost. */

View on GitHub (pinned to 294cab2f9b)

Solutions

  1. Use one of the supported strings: 'trace', 'debug', 'info'/'information', 'warn'/'warning', 'error', 'critical', 'none'.
  2. If you have a LogLevel enum value, pass the enum directly: `configureLogging(LogLevel.Information)`.
  3. Map your custom names to the supported set before calling configureLogging.
  4. If loading from env, validate against a known list before passing.

Example fix

// before
builder.configureLogging(process.env.LOG_LEVEL); // e.g. 'verbose' -> throws

// after
const ALLOWED = ['trace','debug','info','information','warn','warning','error','critical','none'];
const level = ALLOWED.includes(process.env.LOG_LEVEL?.toLowerCase())
  ? process.env.LOG_LEVEL
  : 'warning';
builder.configureLogging(level);
Defensive patterns

Strategy: validation

Validate before calling

const VALID = ['trace','debug','info','information','warn','warning','error','critical','none'];
function safeLogLevel(name) {
  const lower = String(name || '').toLowerCase();
  if (!VALID.includes(lower)) throw new Error(`Unknown log level '${name}'. Valid: ${VALID.join(', ')}`);
  return lower;
}
builder.configureLogging(safeLogLevel(process.env.LOG_LEVEL));

Type guard

function isKnownLogLevelName(name: string): boolean {
  return ['trace','debug','info','information','warn','warning','error','critical','none'].includes(name.toLowerCase());
}

Try / catch

try { builder.configureLogging(input); }
catch (e) {
  if (/Unknown log level/.test(String(e))) {
    builder.configureLogging('warning'); // safe default
  } else throw e;
}

Prevention

When it happens

Trigger: Calling `configureLogging('verbose')`, `configureLogging('INFO')` (this would actually work because matching is case-insensitive), `configureLogging('Informational')`, `configureLogging('all')`, or any string not in the mapping. The lookup at line 34 returns undefined and the function throws.

Common situations: Porting log level names from another library (log4j, pino, winston) that uses different names; typo like 'infomation'; env var with unexpected value; passing a numeric string like '3' instead of the enum.

Related errors


AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06). Data as JSON: /api/errors/d160b9317b389bb7. Report an issue: GitHub.