JsonFileFormatter Class

A FileFormatter that writes one JSON object per log entry.

public sealed class JsonFileFormatter : FileFormatter
Inheritance
FileFormatter JsonFileFormatter

Constructors

NameDescription
JsonFileFormatter()Initializes a new instance of the JsonFileFormatter class.

JsonFileFormatter()

JsonFileFormatter.cs

Initializes a new instance of the JsonFileFormatter class.

public JsonFileFormatter()

Properties

NameDescription
InstanceGets a shared instance of the JsonFileFormatter class.

Gets a shared instance of the JsonFileFormatter class.

public static JsonFileFormatter Instance { get; }

Property value

JsonFileFormatter

Methods

NameDescription
Write<TState>(LogEntry<TState>, DateTimeOffset, FileLoggerOptions, IExternalScopeProvider?, TextWriter)Writes the log message to the specified TextWriter. The line terminator is written by the provider.

Write<TState>(LogEntry<TState>, DateTimeOffset, FileLoggerOptions, IExternalScopeProvider?, TextWriter)

JsonFileFormatter.cs

Writes the log message to the specified TextWriter. The line terminator is written by the provider.

public override void Write<TState>(in LogEntry<TState> logEntry, DateTimeOffset timestamp, FileLoggerOptions options, IExternalScopeProvider? scopeProvider, TextWriter textWriter)

Type parameters

TState
The type of the log entry state.

Parameters

logEntry LogEntry<TState>
The log entry to write.
timestamp DateTimeOffset
The date and time at which the message was logged, in the timezone configured by FileLoggerOptions.UseUtcTimestamp.
options FileLoggerOptions
The options of the provider that created the log entry.
scopeProvider IExternalScopeProvider?
The provider of scope data, or null when the scopes must not be written.
textWriter TextWriter
The writer the message must be written to.

Remarks

The method is called on the thread that logs the message, so the ambient state such as Activity.Current can be read.