Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Allow to set log file prefix and ITextFormatter. #53

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,39 @@ public static LoggerConfiguration RollingFileAlternate(
return configuration.Sink(sink, minimumLevel);
}

/// <summary>
/// Creates an alternative implementation of the rolling file sink with
/// an overload to pass an ITextFormatter.
/// </summary>
/// <param name="configuration"><see cref="LoggerSinkConfiguration"/></param>
/// <param name="formatter">Formatter to control how events are rendered into the file. To control
/// plain text formatting, use the overload that accepts an output template instead.</param>
/// <param name="logDirectory">The names of the directory to be logged</param>
/// <param name="logFilePrefix">The prefix for the log file name.</param>
/// <param name="minimumLevel">Minimum <see cref="LogLevel"/></param>
/// <param name="fileSizeLimitBytes">The size files should grow up to (default 2MB)</param>
/// <param name="retainedFileCountLimit">The maximum number of log files that will be retained,
/// including the current log file. The default is null which is unlimited.</param>
/// <returns></returns>
public static LoggerConfiguration RollingFileAlternate(
this LoggerSinkConfiguration configuration,
ITextFormatter formatter,
string logDirectory,
string logFilePrefix,
LogEventLevel minimumLevel = LevelAlias.Minimum,
long? fileSizeLimitBytes = null,
int? retainedFileCountLimit = null)
{
if (configuration == null)
{
throw new ArgumentNullException("configuration");
}

var sink = new AlternateRollingFileSink(logDirectory, formatter, fileSizeLimitBytes ?? TwoMegabytes,
retainedFileCountLimit, logFilePrefix: logFilePrefix);
return configuration.Sink(sink, minimumLevel);
}

/// <summary>
/// Creates an hourly rolling file sink that rolls files every hour.
/// </summary>
Expand Down