FileLoggerBuilderExtensions Class

Provides extension methods for ILoggingBuilder to add file logging support.

public static class FileLoggerBuilderExtensions

Example

var builder = Host.CreateApplicationBuilder(args);
builder.Logging.AddFile(options =>
{
    options.Directory = "logs";
    options.RollInterval = RollInterval.Daily;
    options.MaxRetainedFiles = 7;
});

Methods

NameDescription
AddFile(ILoggingBuilder)Adds a file logger provider to the logging builder. The options are read from the Logging:File configuration section.
AddFile(ILoggingBuilder, Action<FileLoggerOptions>)Adds a file logger provider configured by the specified delegate.
AddFile(ILoggingBuilder, string)Adds a file logger provider that writes to the specified directory.
AddFile(ILoggingBuilder, string, Action<FileLoggerOptions>)Adds a file logger provider that writes to the specified directory and is configured by the specified delegate.

AddFile overloads

AddFile(ILoggingBuilder)

FileLoggerBuilderExtensions.cs

Adds a file logger provider to the logging builder. The options are read from the Logging:File configuration section.

public static ILoggingBuilder AddFile(this ILoggingBuilder builder)
Parameters
builder ILoggingBuilder
The ILoggingBuilder to add the provider to.
Returns

ILoggingBuilder The ILoggingBuilder so that additional calls can be chained.

AddFile(ILoggingBuilder, Action<FileLoggerOptions>)

FileLoggerBuilderExtensions.cs

Adds a file logger provider configured by the specified delegate.

public static ILoggingBuilder AddFile(this ILoggingBuilder builder, Action<FileLoggerOptions> configure)
Parameters
builder ILoggingBuilder
The ILoggingBuilder to add the provider to.
configure Action<FileLoggerOptions>
A delegate to configure the options of the provider.
Returns

ILoggingBuilder The ILoggingBuilder so that additional calls can be chained.

AddFile(ILoggingBuilder, string)

FileLoggerBuilderExtensions.cs

Adds a file logger provider that writes to the specified directory.

public static ILoggingBuilder AddFile(this ILoggingBuilder builder, string logsDirectory)
Parameters
builder ILoggingBuilder
The ILoggingBuilder to add the provider to.
logsDirectory string
The directory where log files will be written.
Returns

ILoggingBuilder The ILoggingBuilder so that additional calls can be chained.

AddFile(ILoggingBuilder, string, Action<FileLoggerOptions>)

FileLoggerBuilderExtensions.cs

Adds a file logger provider that writes to the specified directory and is configured by the specified delegate.

public static ILoggingBuilder AddFile(this ILoggingBuilder builder, string logsDirectory, Action<FileLoggerOptions> configure)
Parameters
builder ILoggingBuilder
The ILoggingBuilder to add the provider to.
logsDirectory string
The directory where log files will be written.
configure Action<FileLoggerOptions>
A delegate to configure the options of the provider.
Returns

ILoggingBuilder The ILoggingBuilder so that additional calls can be chained.