Skip to content

Logging

shmellyorc edited this page Sep 13, 2026 · 4 revisions

Logging

VOID provides asynchronous process-wide logging through Logger.Instance.

Messages can use levels, categories, composite formatting, exceptions, and custom sinks.

Basic Usage

var logger =
    Logger.Instance;

logger.Debug(
    "Loading level");

logger.Info(
    "Game started");

logger.Warning(
    "Low memory warning");

try
{
    LoadSomething();
}
catch (Exception ex)
{
    logger.Error(
        ex,
        "Failed to load content");
}

Formatted messages use the normal composite-format style:

logger.Info(
    "Player position: {0}, {1}",
    x,
    y);

Log Levels

Level Use
Debug Development/troubleshooting detail
Info Normal application operation
Warning Potential problem that can continue
Error Failure that may still allow continued operation
Fatal Severe failure; writes and flushes immediately
None Suppresses normal log output when used as the minimum level

Set the minimum:

logger.SetLevel(
    LogLevel.Info);

Messages below the configured level are discarded before formatted arguments are expanded.

Categories

Use the WithCategory methods to group output by subsystem:

logger.InfoWithCategory(
    "Network",
    "Connected to server");

logger.WarningWithCategory(
    "Audio",
    "Voice pool is nearly full");

logger.ErrorWithCategory(
    "Assets",
    exception,
    "Failed to load player texture");

Fatal vs Critical

Fatal writes the entry and flushes queued logs:

Logger.Instance.Fatal(
    "Renderer initialization failed");

Critical is intentionally stronger.

It writes crash-style details, includes a stack trace, flushes pending logs, and then throws an InvalidOperationException:

Logger.Instance.CriticalWithCategory(
    "Renderer",
    "Framebuffer creation failed");

Use Critical only when continuing execution is not valid.

Automatic Sinks

When Game starts, VOID adds:

  • ConsoleSink
  • FileSink

The logger level and file retention settings come from GameSettings.

Configure them before Build():

var settings =
    GameSettings.Instance
        .SetLogMinLevel(
            LogLevel.Info)
        .SetLogMaxFileSizeMB(10)
        .SetLogMaxFiles(10)
        .Build();

Log files are written under Game.Instance.ApplicationLogFolder.

See Game Class → Application Folders.

File Rotation

FileSink creates daily files:

log_13-09-2026.txt

When a file reaches the configured size limit, the sink rolls to numbered files:

log_13-09-2026_1.txt
log_13-09-2026_2.txt

Retention cleanup removes older matching log files once the configured maximum count is exceeded.

Performance and Threading

The logger:

  • queues entries for a background writer thread
  • processes entries in batches
  • bounds the queue to prevent unlimited memory growth
  • serializes sink writes
  • isolates sink failures so one sink does not stop the others
  • can be called from multiple threads

The current queue limit is 10,000 entries and the worker processes batches of up to 100 entries.

Flushing

Force queued entries to be written:

Logger.Instance.Flush();

Fatal and Critical paths flush automatically.

Custom Sinks

Implement ILogSink:

public sealed class DatabaseSink
    : ILogSink
{
    public void Write(
        LogEntry entry)
    {
        // Store or forward the entry.
    }
}

Register it:

Logger.Instance.AddSink(
    new DatabaseSink());

Remove it later if needed:

Logger.Instance.RemoveSink(
    sink);

See Extensibility → Custom Log Sink.


Back to Home

Clone this wiki locally