aspnetboilerplate/aspnetboilerplate · error · AbpException

Unknown LogSeverity value:

Error message

Unknown LogSeverity value: 

What it means

Thrown by the Abp LoggerExtensions.Log(this ILogger, LogSeverity, string) extension when it receives a LogSeverity enum value it does not recognize. The switch handles Fatal/Error/Warn/Info/Debug; anything else hits the default case. In practice this happens with an invalid cast or out-of-range value.

Solutions

  1. Only pass valid LogSeverity values (Fatal, Error, Warn, Info, Debug)
  2. Use Enum.TryParse<LogSeverity>(value, out var sev) before logging instead of a raw cast
  3. Fix the mapping code that converts external log levels to LogSeverity and add an explicit default mapping (e.g. Error for unknown)
  4. If mapping from another enum, match on that enum's cases and map each explicitly

Example fix

// before
logger.Log((LogSeverity)logLevelInt, message); // logLevelInt=42
// after
if (Enum.IsDefined(typeof(LogSeverity), logLevelInt))
    logger.Log((LogSeverity)logLevelInt, message);
else
    logger.Error(message);
Defensive patterns

Strategy: type-guard

Validate before calling

bool IsValidSeverity(LogSeverity severity) =>
    severity == LogSeverity.Fatal || severity == LogSeverity.Error || severity == LogSeverity.Warn ||
    severity == LogSeverity.Info || severity == LogSeverity.Debug;

Type guard

static bool IsDefinedLogSeverity(LogSeverity s) => Enum.IsDefined(typeof(LogSeverity), s);

Try / catch

try { logger.Log(severity, message); }
catch (AbpException ex) when (ex.Message.Contains("Unknown LogSeverity value"))
{
    logger.Error(message); // safe fallback
}

Prevention

When it happens

Trigger: Calling logger.Log((LogSeverity)99, "msg") or casting an int/other enum into LogSeverity that is not a defined member of the Abp.Logging.LogSeverity enum.

Common situations: Mapping log levels from another framework with an unverified cast; persisted log-level int out of range; a second enum type accidentally used where LogSeverity was expected.

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 aspnetboilerplate/aspnetboilerplate@2323c13a15 (2026-09-08). Data as JSON: /api/errors/85c356a0e44a81d8. Report an issue: GitHub.

Appendix: source

Thrown at src/Abp/Logging/LoggerExtensions.cs:31

            switch (severity)
            {
                case LogSeverity.Fatal:
                    logger.Fatal(message);
                    break;
                case LogSeverity.Error:
                    logger.Error(message);
                    break;
                case LogSeverity.Warn:
                    logger.Warn(message);
                    break;
                case LogSeverity.Info:
                    logger.Info(message);
                    break;
                case LogSeverity.Debug:
                    logger.Debug(message);
                    break;
                default:
                    throw new AbpException("Unknown LogSeverity value: " + severity);
            }
        }

        public static void Log(this ILogger logger, LogSeverity severity, string message, Exception exception)
        {
            switch (severity)
            {
                case LogSeverity.Fatal:
                    logger.Fatal(message, exception);
                    break;
                case LogSeverity.Error:
                    logger.Error(message, exception);
                    break;
                case LogSeverity.Warn:
                    logger.Warn(message, exception);
                    break;
                case LogSeverity.Info:
                    logger.Info(message, exception);

View on GitHub (pinned to 2323c13a15)