Skip to content

Commit

Permalink
Allow to set log file prefix and ITextFormatter.
Browse files Browse the repository at this point in the history
  • Loading branch information
markusschaber committed Jun 20, 2023
1 parent 7937c7d commit d459d97
Showing 1 changed file with 33 additions and 0 deletions.
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

0 comments on commit d459d97

Please sign in to comment.