Skip to content

Log Levels

thushxr edited this page Jun 27, 2026 · 1 revision

Log Levels

Six severity levels, ordered from most verbose to most severe. Plus None, used only to switch logging off.

Level Numeric Text tag Icon Use it for…
Trace 0 TRACE The most fine-grained diagnostic detail — method entry/exit, loop values. Normally off in production (noisy/expensive).
Debug 1 DEBUG 🟦 Developer-facing diagnostics — cache hits/misses, internal state, chosen code paths. Usually off in production.
Information 2 INFO 🟩 Normal application flow and business milestones — "started", "user signed in", "job done". The default minimum level.
Warning 3 WARN 🟨 Something unexpected, but the app recovered — a retry, a fallback, a deprecated path, nearing a limit.
Error 4 ERROR 🟥 The current operation failed — typically a caught exception. The app keeps running.
Critical 5 CRITICAL 🟪 The app or a major subsystem is unusable — out of memory, failed startup, data loss. The "wake someone up" level.
None 6 Not a real entry. Set as the minimum level to disable all logging.

Calling them

Every level has two overloads — a message (with optional template values) and an exception variant:

Log.Trace("Entered {method}", nameof(Process));
Log.Debug("Cache miss for {key}", key);
Log.Information("User {userId} signed in", userId);
Log.Warning("Retry {attempt} of {max}", attempt, max);
Log.Error("Request to {url} failed", url);
Log.Error(ex, "Request to {url} failed", url);     // with exception
Log.Critical(ex, "Unrecoverable startup failure");

The same methods exist on Log<T> (with plain-string messages — see Log vs Log<T>).

Filtering by minimum level

The configured minimum level is the primary volume control: any entry below it is dropped before any formatting work happens, so suppressed logs are cheap.

Log.Configure(o => o.SetMinimumLevel(LogLevel.Warning));

Log.Information("ignored");   // below minimum → dropped
Log.Warning("kept");          // at/above minimum → written

Because the levels are ordered (Trace = 0 … Critical = 5), "minimum level Warning" means Warning, Error, and Critical are written; Trace, Debug, Information are dropped.

Change it at runtime any time:

Log.MinimumLevel = LogLevel.Debug;

Turning logging off

Log.MinimumLevel = LogLevel.None;   // nothing is ever written

Since None (6) is higher than every real level, nothing clears the bar.

Choosing the right level (quick guide)

  • Is the app/process dead or about to be? → Critical
  • Did this operation fail (exception, request rejected)? → Error
  • Did something odd happen but we coped? → Warning
  • Is this the normal story of what the app is doing? → Information
  • Is this only useful while debugging? → Debug
  • Is this trace-level firehose detail? → Trace

Clone this wiki locally