Vixen
02b45cc4
csharp
public sealed class ZLoggerFileSink

The log on disk: JSON lines, rolling by day and by size, written on a background thread by ZLogger.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

The file is what a player attaches to a bug report and what a dedicated server keeps between restarts, so it is the one sink whose output is read by machines as often as by people. JSON lines rather than formatted text for exactly that reason: jq, an ingestion pipeline and a support engineer can all read it, and the structured fields the [LoggerMessage] call site declared are still fields rather than having been flattened into a sentence.

Why ZLogger and not thirty more lines of our own. ADR-008 names it, and the reason is the half that is genuinely hard: an asynchronous writer with a bounded background buffer, UTF-8 formatting straight into that buffer with no intermediate string, and file rolling that does not lose the record being written when the file turns over. That is the same argument as for the ring buffer being ours — this half is a solved problem and that half is engine-specific.

This sink forwards the caller's state rather than a formatted line. It is the reason it derives from LogSink rather than LogRecordSink: a LogRecord holds a String that has already been assembled, and handing that to ZLogger would pay for the allocation this sink exists to avoid and write a JSON document whose only field is a sentence.

Rate limiting works here too, and what a suppressed run leaves behind is a record of its own carrying SuppressedCount as a field — appending "(repeated N times)" to a message that is stored structured would be putting the count in the one place a query cannot reach it.

Fields and properties (3)

  • public const string DefaultFileNamePrefix

    The file name prefix used when none is given.

  • public const int DefaultRollingSizeKilobytes

    How large a file grows before it rolls, when nothing else is asked for.

  • public string DirectoryPath

    The directory this sink was given, or empty when it was constructed with a path selector instead and the directory is therefore the selector's business.

Methods (4)

  • public ZLoggerFileSink(string directoryPath, string fileNamePrefix = "vixen", int rollingSizeKilobytes = 65536, LogLevel minimumLevel = Information, LogFilter? filter = null)

    Creates a sink writing rolling JSON-line files into a directory.

  • public ZLoggerFileSink(Func<DateTimeOffset, int, string> filePathSelector, int rollingSizeKilobytes = 65536, LogLevel minimumLevel = Information, LogFilter? filter = null)

    Creates a sink whose file names are chosen by a caller-supplied selector.

  • public override ILogger CreateLogger(string categoryName)

    Creates a new ILogger instance.

  • protected override void Dispose(bool disposing)

Used by (3)

  • AppBuilderVixen.App.Hosting
  • CategoryLoggerVixen.Core.Diagnostics
  • SinkTestsVixen.Core.Diagnostics.Tests