Skip to content

Commit d459d97

Browse files
committed
Allow to set log file prefix and ITextFormatter.
closes BedeGaming#39
1 parent 7937c7d commit d459d97

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/Serilog.Sinks.RollingFileAlternate/LoggerConfigurationExtensions.cs

+33
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,39 @@ public static LoggerConfiguration RollingFileAlternate(
116116
return configuration.Sink(sink, minimumLevel);
117117
}
118118

119+
/// <summary>
120+
/// Creates an alternative implementation of the rolling file sink with
121+
/// an overload to pass an ITextFormatter.
122+
/// </summary>
123+
/// <param name="configuration"><see cref="LoggerSinkConfiguration"/></param>
124+
/// <param name="formatter">Formatter to control how events are rendered into the file. To control
125+
/// plain text formatting, use the overload that accepts an output template instead.</param>
126+
/// <param name="logDirectory">The names of the directory to be logged</param>
127+
/// <param name="logFilePrefix">The prefix for the log file name.</param>
128+
/// <param name="minimumLevel">Minimum <see cref="LogLevel"/></param>
129+
/// <param name="fileSizeLimitBytes">The size files should grow up to (default 2MB)</param>
130+
/// <param name="retainedFileCountLimit">The maximum number of log files that will be retained,
131+
/// including the current log file. The default is null which is unlimited.</param>
132+
/// <returns></returns>
133+
public static LoggerConfiguration RollingFileAlternate(
134+
this LoggerSinkConfiguration configuration,
135+
ITextFormatter formatter,
136+
string logDirectory,
137+
string logFilePrefix,
138+
LogEventLevel minimumLevel = LevelAlias.Minimum,
139+
long? fileSizeLimitBytes = null,
140+
int? retainedFileCountLimit = null)
141+
{
142+
if (configuration == null)
143+
{
144+
throw new ArgumentNullException("configuration");
145+
}
146+
147+
var sink = new AlternateRollingFileSink(logDirectory, formatter, fileSizeLimitBytes ?? TwoMegabytes,
148+
retainedFileCountLimit, logFilePrefix: logFilePrefix);
149+
return configuration.Sink(sink, minimumLevel);
150+
}
151+
119152
/// <summary>
120153
/// Creates an hourly rolling file sink that rolls files every hour.
121154
/// </summary>

0 commit comments

Comments
 (0)