Skip to content

Built-in Formatters

DefaultFormatter

The default formatter used by Logger and all local sinks.

Output format: [MM-dd HH:mm:ss] [LEVEL] filename[line]: message

// [06-01 10:00:00] [INFO] Player.cs[42]: Game started!

The timestamp can be toggled or configured:

var formatter = new DefaultFormatter
{
    IncludeTimestamp = false,                 // default: true
    TimestampFormat = "yyyy-MM-dd HH:mm:ss"   // default: "MM-dd HH:mm:ss"
};
// Set TimestampFormat to null for locale-based:
// "M/d/yyyy h:mm tt" (en-US), "dd.MM.yyyy H:mm" (de-DE), etc.

JsonFormatter

Produces a structured JSON object using Newtonsoft.Json.

{
  "timestamp": "2026-05-30T14:32:01.0000000Z",
  "message": "Game started!",
  "file": "D:/Projects/MyGame/Assets/Scripts/Player.cs",
  "line": 42,
  "level": "Info",
  "stackTrace": null
}

Used as the default formatter for HttpSink and WebSocketSink.

DiscordFormatter

Wraps output in Discord webhook-compatible JSON with emoji level indicators.

Emoji map:

Level Emoji
Debug :mag:
Info :information_source:
Warning :warning:
Error :x:
Assert :x:

Output format (wrapped in { "content": "..." }):

**LEVEL** | MyGame | v1.0.0 | message | file:line | HH:mm:ss

The app name and version are automatically read from Application.productName and Application.version.

Properties:

var formatter = new DiscordFormatter();
formatter.IncludeFileInfo = true;  // default: true

SlackFormatter

Produces Slack Block Kit JSON with emoji level indicators.

Emoji map is the same as DiscordFormatter.

Block Kit structure:

{
  "text": "...",
  "blocks": [{ "type": "section", "text": { "type": "mrkdwn", "text": "..." } }],
  "channel": null,
  "username": null,
  "icon_url": null,
  "icon_emoji": null
}

The app name and version are automatically read from Application.productName and Application.version (in Project Settings -> Player).

Customization:

var formatter = new SlackFormatter
{
    Channel = "#game-logs",
    Username = "Logix",
    IconEmoji = ":robot:",
    IconUrl = "https://example.com/icon.png"
};

LokiFormatter

Produces the Grafana Loki push API format with stream labels and optional file metadata.

Output structure:

{
  "streams": [{
    "stream": { "level": "info", "app": "MyGame", "version": "1.0.0", ... },
    "values": [[ "1736000000000000000", "message text", { "file": "...", "line": "42" } ]]
  }]
}
  • Timestamp is in nanoseconds (Unix epoch * 100)
  • "app" and "version" labels are automatically set from Application.productName and Application.version
  • IncludeFileInfo -> when true, adds file and line as per-entry metadata
  • Custom Labels dictionary -> additional stream labels
var formatter = new LokiFormatter();
formatter.IncludeFileInfo = true;
formatter.Labels["environment"] = "production";