Skip to content

Formatters

Formatters convert a LogMessage into a string that sinks can deliver. Every formatter implements IMessageFormatter:

public interface IMessageFormatter
{
    string Format(LogMessage logMessage);
}

Where formatters are used

  • Logger.Formatter -> global default formatter (used when no per-sink formatter is set)
  • Sink.Formatter -> per-sink override (all sinks support this: FileLogSink, ConsoleLogSink, UnityLogSink, and CloudLogSink subclasses)
// Set the global default
Log.Container.Logger.Formatter = new JsonFormatter();

// Override for a specific sink
myDiscordSink.Formatter = new DiscordFormatter();
myFileSink.Formatter = new JsonFormatter();

Built-in formatters

Formatter Default for Output
DefaultFormatter Logger, local sinks [MM-dd HH:mm:ss] [LEVEL] file[line]: message
JsonFormatter HttpSink, WebSocketSink Structured JSON with all fields
DiscordFormatter DiscordSink Discord webhook { "content": "..." } JSON with emoji
SlackFormatter SlackSink Slack Block Kit JSON with emoji
LokiFormatter LokiSink Loki push API { "streams": [...] } JSON