Skip to content

API Reference

thushxr edited this page Jun 27, 2026 · 1 revision

API Reference

The entire public surface lives in the Thushar.Logging namespace. There are four public types:

  • Log — the static logger (message templates)
  • Log<T> — the typed logger (class/method context)
  • LoggerOptions — configuration
  • LogLevel — severity enum

Log

public static class Log

The non-generic static logger. Uses message templates; values become structured fields. See Message Templates.

Configuration & state

Member Signature Description
Configure static void Configure(Action<LoggerOptions> configure) Apply configuration. Call once at startup; safe to call again to reconfigure. Throws ArgumentNullException if configure is null.
MinimumLevel static LogLevel MinimumLevel { get; set; } Get or set the minimum level without a full reconfigure.
TraceId static string? TraceId { get; } The trace id for the current async flow, or null.
SetTraceId static void SetTraceId(string? traceId = null) Set the ambient trace id for the current async flow (a new GUID when omitted).
BeginTraceScope static IDisposable BeginTraceScope(string? traceId = null) Begin a trace scope; restores the previous id on dispose. New GUID when omitted.

Logging methods

Each level has two overloads:

static void Level(string message, params object?[] args);
static void Level(Exception exception, string message, params object?[] args);

where Level is one of:

Method Level
Trace LogLevel.Trace
Debug LogLevel.Debug
Information LogLevel.Information
Warning LogLevel.Warning
Error LogLevel.Error
Critical LogLevel.Critical
  • message — a template; {placeholder} tokens are filled positionally from args.
  • args — values for the placeholders, matched left to right.
  • exception — appended after the message (text) or written as the exception field (JSON).
Log.Information("User {userId} logged in", 42);
Log.Error(ex, "Failed to save order {orderId}", orderId);

Log<T>

public static class Log<T>

The typed logger. Stamps each entry with the source class (typeof(T).Name, cached) and the calling method ([CallerMemberName]). Messages are plain strings — no template substitution. See Log vs Log<T>.

Logging methods

Each level has two overloads:

static void Level(string message, [CallerMemberName] string? method = null);
static void Level(Exception exception, string message, [CallerMemberName] string? method = null);

with the same six Level names as Log.

Do not pass the method argument — the compiler fills it via [CallerMemberName].

public class OrderService
{
    public void Process()
    {
        Log<OrderService>.Information("Processing started");
        // class = "OrderService", method = "Process"
        Log<OrderService>.Error(ex, "Checkout failed");
    }
}

LoggerOptions

public sealed class LoggerOptions

Passed to your Configure callback. Each fluent method returns the same instance, so calls chain. All toggles apply to both text and JSON. Full details in Configuration.

Properties

Property Type Default
MinimumLevel LogLevel Information
Structured bool false
UseUtcTimestamp bool true
TimestampFormat string "yyyy-MM-dd HH:mm:ss.fff"
IncludeTimestamp bool true
IncludeLevel bool true
IncludeColorIcon bool true
IncludeTraceId bool true
IncludeClassName bool true
IncludeMethodName bool true

Fluent methods

Method Sets
UseStructured(bool enabled = true) Structured
SetMinimumLevel(LogLevel level) MinimumLevel
UseUtc(bool enabled = true) UseUtcTimestamp
AddTimestamp(bool enabled = true) IncludeTimestamp
AddLevel(bool enabled = true) IncludeLevel
AddColorIcon(bool enabled = true) IncludeColorIcon
AddTraceId(bool enabled = true) IncludeTraceId
UseClassName(bool enabled = true) IncludeClassName (Log<T> only)
UseMethodName(bool enabled = true) IncludeMethodName (Log<T> only)
Log.Configure(o => o
    .UseStructured()
    .SetMinimumLevel(LogLevel.Debug)
    .AddColorIcon(false));

LogLevel

public enum LogLevel

Member Value
Trace 0
Debug 1
Information 2
Warning 3
Error 4
Critical 5
None 6

Ordered from most verbose to most severe. None is not a real entry — use it as the minimum level to disable logging. See Log Levels for guidance.

Clone this wiki locally