FileLoggerOptions Class
Options for the FileLoggerProvider.
public sealed class FileLoggerOptionsConstructors
| Name | Description |
|---|---|
| FileLoggerOptions() |
FileLoggerOptions()
FileLoggerOptions.cspublic FileLoggerOptions()No documentation is available.
Properties
| Name | Description |
|---|---|
| Append | 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. |
| Compression | Gets or sets the algorithm used to compress the log files. Defaults to LogFileCompression.None. |
| CompressionLevel | Gets or sets the compression level. Defaults to CompressionLevel.Optimal. This value is ignored when FileLoggerOptions.Compression is LogFileCompression.None. |
| CompressionMode | Gets or sets when the log files are compressed. Defaults to LogFileCompressionMode.Continuous. This value is ignored when FileLoggerOptions.Compression is LogFileCompression.None. |
| Directory | Gets or sets the directory where log files are written. This value is required. |
| EscapeControlCharacters | 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. |
| FileNameExtension | Gets or sets the extension of the log file names, including the leading dot. Defaults to .log. |
| FileNamePrefix | Gets or sets the prefix added at the beginning of the log file names. Defaults to an empty string. |
| FlushInterval | Gets or sets the maximum duration between two flushes when messages are logged continuously. Defaults to 1 second. |
| Formatter | Gets or sets the formatter used to write the log entries. When null, the formatter is resolved from FileLoggerOptions.FormatterName. |
| FormatterName | 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. |
| IncludeActivityTracking | 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. |
| IncludeCategory | Gets or sets a value indicating whether the category is included in the log messages. Defaults to true. |
| IncludeEventId | Gets or sets a value indicating whether the event id is included in the log messages. Defaults to false. |
| IncludeLogLevel | Gets or sets a value indicating whether the log level is included in the log messages. Defaults to true. |
| IncludeProcessIdInFileName | Gets or sets a value indicating whether the identifier of the current process is part of the log file names. Defaults to true. |
| IncludeScopes | Gets or sets a value indicating whether scopes are included in the log messages. Defaults to false. |
| IncludeThreadId | 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. |
| MaxFileSizeInBytes | Gets or sets the maximum size of a log file, in bytes, after which a new file is created. Defaults to null (no limit). |
| MaxQueueLength | Gets or sets the maximum number of messages that can be queued before FileLoggerOptions.QueueFullMode applies. Defaults to 1024. |
| MaxRetainedFiles | 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). |
| MinLevel | Gets or sets the minimum level of the messages written to the file. Defaults to LogLevel.Trace. |
| QueueFullMode | Gets or sets the behavior when the message queue is full. Defaults to FileLoggerQueueFullMode.Wait. |
| RollInterval | Gets or sets how often a new log file is created based on time. Defaults to RollInterval.None. |
| TimestampFormat | Gets or sets the format string used to format the timestamp of the log messages. Set it to null to omit the timestamp. |
| UnixCreateMode | 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. |
| UseShortCategoryName | 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. |
| UseUtcTimestamp | Gets or sets a value indicating whether the UTC timezone is used to format the timestamps. Defaults to true. |
Append
FileLoggerOptions.csGets 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
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:
FileLoggerOptions.RollIntervalmust be set.RollInterval.Noneincludes the seconds in the name, so the name changes on every start.FileLoggerOptions.IncludeProcessIdInFileNamemust befalseto reuse a file across restarts, as the identifier of the process changes.
With the default values of these two options, a new file is created on every start even when this option is true.
Compression
FileLoggerOptions.csGets or sets the algorithm used to compress the log files. Defaults to LogFileCompression.None.
public LogFileCompression Compression { get; set; }Property value
CompressionLevel
FileLoggerOptions.csGets 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
CompressionMode
FileLoggerOptions.csGets 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
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.
Directory
FileLoggerOptions.csEscapeControlCharacters
FileLoggerOptions.csGets 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
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.csFileNamePrefix
FileLoggerOptions.csFlushInterval
FileLoggerOptions.csGets or sets the maximum duration between two flushes when messages are logged continuously. Defaults to 1 second.
public TimeSpan FlushInterval { get; set; }Property value
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.
Formatter
FileLoggerOptions.csGets 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
FormatterName
FileLoggerOptions.csGets 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
IncludeActivityTracking
FileLoggerOptions.csIncludeCategory
FileLoggerOptions.csIncludeEventId
FileLoggerOptions.csIncludeLogLevel
FileLoggerOptions.csIncludeProcessIdInFileName
FileLoggerOptions.csIncludeScopes
FileLoggerOptions.csIncludeThreadId
FileLoggerOptions.csMaxFileSizeInBytes
FileLoggerOptions.csMaxQueueLength
FileLoggerOptions.csGets 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
MaxRetainedFiles
FileLoggerOptions.csMinLevel
FileLoggerOptions.csGets or sets the minimum level of the messages written to the file. Defaults to LogLevel.Trace.
public LogLevel MinLevel { get; set; }Property value
QueueFullMode
FileLoggerOptions.csGets or sets the behavior when the message queue is full. Defaults to FileLoggerQueueFullMode.Wait.
public FileLoggerQueueFullMode QueueFullMode { get; set; }Property value
RollInterval
FileLoggerOptions.csGets or sets how often a new log file is created based on time. Defaults to RollInterval.None.
public RollInterval RollInterval { get; set; }Property value
TimestampFormat
FileLoggerOptions.csUnixCreateMode
FileLoggerOptions.csGets 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
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.