FileLoggerOptions Class

Options for the FileLoggerProvider.

public sealed class FileLoggerOptions

Constructors

NameDescription
FileLoggerOptions()

FileLoggerOptions()

FileLoggerOptions.cs
public FileLoggerOptions()

No documentation is available.

Properties

NameDescription
AppendGets or sets a value indicating whether an existing log file is reused instead of creating a new one. Defaults to false. When a matching file is already in use by another process, a new file is created.
CompressionGets or sets the algorithm used to compress the log files. Defaults to LogFileCompression.None.
CompressionLevelGets or sets the compression level. Defaults to CompressionLevel.Optimal. This value is ignored when FileLoggerOptions.Compression is LogFileCompression.None.
CompressionModeGets or sets when the log files are compressed. Defaults to LogFileCompressionMode.Continuous. This value is ignored when FileLoggerOptions.Compression is LogFileCompression.None.
DirectoryGets or sets the directory where log files are written. This value is required.
EscapeControlCharactersGets or sets a value indicating whether the control characters of the messages, the exceptions and the scopes are escaped, so a log entry always spans a single line. Defaults to false.
FileNameExtensionGets or sets the extension of the log file names, including the leading dot. Defaults to .log.
FileNamePrefixGets or sets the prefix added at the beginning of the log file names. Defaults to an empty string.
FlushIntervalGets or sets the maximum duration between two flushes when messages are logged continuously. Defaults to 1 second.
FormatterGets or sets the formatter used to write the log entries. When null, the formatter is resolved from FileLoggerOptions.FormatterName.
FormatterNameGets or sets the name of the formatter to use. Supported values are FileFormatterNames.Simple and FileFormatterNames.Json. This value is ignored when FileLoggerOptions.Formatter is set.
IncludeActivityTrackingGets or sets a value indicating whether the trace id and the span id of the current Activity are included in the log messages. Defaults to false.
IncludeCategoryGets or sets a value indicating whether the category is included in the log messages. Defaults to true.
IncludeEventIdGets or sets a value indicating whether the event id is included in the log messages. Defaults to false.
IncludeLogLevelGets or sets a value indicating whether the log level is included in the log messages. Defaults to true.
IncludeProcessIdInFileNameGets or sets a value indicating whether the identifier of the current process is part of the log file names. Defaults to true.
IncludeScopesGets or sets a value indicating whether scopes are included in the log messages. Defaults to false.
IncludeThreadIdGets or sets a value indicating whether the identifier of the thread that logged the message is included in the log messages. Defaults to false.
MaxFileSizeInBytesGets or sets the maximum size of a log file, in bytes, after which a new file is created. Defaults to null (no limit).
MaxQueueLengthGets or sets the maximum number of messages that can be queued before FileLoggerOptions.QueueFullMode applies. Defaults to 1024.
MaxRetainedFilesGets or sets the maximum number of log files to keep in the directory. Older files are deleted when a new file is created. Defaults to null (no limit).
MinLevelGets or sets the minimum level of the messages written to the file. Defaults to LogLevel.Trace.
QueueFullModeGets or sets the behavior when the message queue is full. Defaults to FileLoggerQueueFullMode.Wait.
RollIntervalGets or sets how often a new log file is created based on time. Defaults to RollInterval.None.
TimestampFormatGets or sets the format string used to format the timestamp of the log messages. Set it to null to omit the timestamp.
UnixCreateModeGets or sets the Unix file mode applied to the log files when they are created. Defaults to null, which uses the default mode of the platform.
UseShortCategoryNameGets or sets a value indicating whether only the last segment of the category is written, for instance Program instead of Sample.Program. Defaults to false.
UseUtcTimestampGets or sets a value indicating whether the UTC timezone is used to format the timestamps. Defaults to true.

Gets or sets a value indicating whether an existing log file is reused instead of creating a new one. Defaults to false. When a matching file is already in use by another process, a new file is created.

public bool Append { get; set; }

Property value

bool

Remarks

A file is reused only when its name matches the name the provider computes when it starts, so this option has no effect unless the name is stable:

With the default values of these two options, a new file is created on every start even when this option is true.

Gets or sets the algorithm used to compress the log files. Defaults to LogFileCompression.None.

public LogFileCompression Compression { get; set; }

Property value

LogFileCompression

CompressionLevel

FileLoggerOptions.cs

Gets or sets the compression level. Defaults to CompressionLevel.Optimal. This value is ignored when FileLoggerOptions.Compression is LogFileCompression.None.

public CompressionLevel CompressionLevel { get; set; }

Property value

CompressionLevel

CompressionMode

FileLoggerOptions.cs

Gets or sets when the log files are compressed. Defaults to LogFileCompressionMode.Continuous. This value is ignored when FileLoggerOptions.Compression is LogFileCompression.None.

public LogFileCompressionMode CompressionMode { get; set; }

Property value

LogFileCompressionMode

Remarks

FileLoggerOptions.Append is ignored when the messages are compressed continuously, as appending to a compressed file would produce a file that most tools cannot read.

Gets or sets the directory where log files are written. This value is required.

public string? Directory { get; set; }

Property value

string?

EscapeControlCharacters

FileLoggerOptions.cs

Gets or sets a value indicating whether the control characters of the messages, the exceptions and the scopes are escaped, so a log entry always spans a single line. Defaults to false.

public bool EscapeControlCharacters { get; set; }

Property value

bool

Remarks

A message containing a line break is written as-is by default, so a value coming from an untrusted source can forge additional log entries. Set this option to true when the messages can contain untrusted data. The stack traces are then written on a single line, which is harder to read. This option is only used by SimpleFileFormatter, as JsonFileFormatter already escapes the control characters.

FileNameExtension

FileLoggerOptions.cs

Gets or sets the extension of the log file names, including the leading dot. Defaults to .log.

public string FileNameExtension { get; set; }

Property value

string

FileNamePrefix

FileLoggerOptions.cs

Gets or sets the prefix added at the beginning of the log file names. Defaults to an empty string.

public string FileNamePrefix { get; set; }

Property value

string

Gets or sets the maximum duration between two flushes when messages are logged continuously. Defaults to 1 second.

public TimeSpan FlushInterval { get; set; }

Property value

TimeSpan

Remarks

The pending messages are always flushed as soon as the queue is empty, so this value only matters when the logger cannot keep up with the messages.

Gets or sets the formatter used to write the log entries. When null, the formatter is resolved from FileLoggerOptions.FormatterName.

public FileFormatter? Formatter { get; set; }

Property value

FileFormatter?

Gets or sets the name of the formatter to use. Supported values are FileFormatterNames.Simple and FileFormatterNames.Json. This value is ignored when FileLoggerOptions.Formatter is set.

public string FormatterName { get; set; }

Property value

string

IncludeActivityTracking

FileLoggerOptions.cs

Gets or sets a value indicating whether the trace id and the span id of the current Activity are included in the log messages. Defaults to false.

public bool IncludeActivityTracking { get; set; }

Property value

bool

IncludeCategory

FileLoggerOptions.cs

Gets or sets a value indicating whether the category is included in the log messages. Defaults to true.

public bool IncludeCategory { get; set; }

Property value

bool

IncludeEventId

FileLoggerOptions.cs

Gets or sets a value indicating whether the event id is included in the log messages. Defaults to false.

public bool IncludeEventId { get; set; }

Property value

bool

IncludeLogLevel

FileLoggerOptions.cs

Gets or sets a value indicating whether the log level is included in the log messages. Defaults to true.

public bool IncludeLogLevel { get; set; }

Property value

bool

IncludeProcessIdInFileName

FileLoggerOptions.cs

Gets or sets a value indicating whether the identifier of the current process is part of the log file names. Defaults to true.

public bool IncludeProcessIdInFileName { get; set; }

Property value

bool

Gets or sets a value indicating whether scopes are included in the log messages. Defaults to false.

public bool IncludeScopes { get; set; }

Property value

bool

IncludeThreadId

FileLoggerOptions.cs

Gets or sets a value indicating whether the identifier of the thread that logged the message is included in the log messages. Defaults to false.

public bool IncludeThreadId { get; set; }

Property value

bool

MaxFileSizeInBytes

FileLoggerOptions.cs

Gets or sets the maximum size of a log file, in bytes, after which a new file is created. Defaults to null (no limit).

public long? MaxFileSizeInBytes { get; set; }

Property value

long?

MaxQueueLength

FileLoggerOptions.cs

Gets or sets the maximum number of messages that can be queued before FileLoggerOptions.QueueFullMode applies. Defaults to 1024.

public int MaxQueueLength { get; set; }

Property value

int

MaxRetainedFiles

FileLoggerOptions.cs

Gets or sets the maximum number of log files to keep in the directory. Older files are deleted when a new file is created. Defaults to null (no limit).

public int? MaxRetainedFiles { get; set; }

Property value

int?

Gets or sets the minimum level of the messages written to the file. Defaults to LogLevel.Trace.

public LogLevel MinLevel { get; set; }

Property value

LogLevel

Gets or sets the behavior when the message queue is full. Defaults to FileLoggerQueueFullMode.Wait.

public FileLoggerQueueFullMode QueueFullMode { get; set; }

Gets or sets how often a new log file is created based on time. Defaults to RollInterval.None.

public RollInterval RollInterval { get; set; }

Property value

RollInterval

TimestampFormat

FileLoggerOptions.cs

Gets or sets the format string used to format the timestamp of the log messages. Set it to null to omit the timestamp.

public string? TimestampFormat { get; set; }

Property value

string?

UnixCreateMode

FileLoggerOptions.cs

Gets or sets the Unix file mode applied to the log files when they are created. Defaults to null, which uses the default mode of the platform.

public UnixFileMode? UnixCreateMode { get; set; }

Property value

UnixFileMode?

Remarks

The default mode of most Unix systems makes the log files readable by every local user. Set this option to UnixFileMode.UserRead | UnixFileMode.UserWrite when the messages can contain sensitive data. The value is ignored on Windows, and the mode is still filtered by the umask of the process. The mode of the directory is not changed.

UseShortCategoryName

FileLoggerOptions.cs

Gets or sets a value indicating whether only the last segment of the category is written, for instance Program instead of Sample.Program. Defaults to false.

public bool UseShortCategoryName { get; set; }

Property value

bool

UseUtcTimestamp

FileLoggerOptions.cs

Gets or sets a value indicating whether the UTC timezone is used to format the timestamps. Defaults to true.

public bool UseUtcTimestamp { get; set; }

Property value

bool