@@ -135,11 +135,12 @@ public static LoggerConfiguration File(
135
135
/// <param name="shared">Allow the log file to be shared by multiple processes. The default is false.</param>
136
136
/// <param name="flushToDiskInterval">If provided, a full disk flush will be performed periodically at the specified interval.</param>
137
137
/// <param name="rollingInterval">The interval at which logging will roll over to a new file.</param>
138
- /// <param name="rollOnFileSizeLimit">If <code>true</code>, a new file will be created when the file size limit is reached. Filenames
138
+ /// <param name="rollOnFileSizeLimit">If <code>true</code>, a new file will be created when the file size limit is reached. Filenames
139
139
/// will have a number appended in the format <code>_NNN</code>, with the first filename given no number.</param>
140
140
/// <param name="retainedFileCountLimit">The maximum number of log files that will be retained,
141
141
/// including the current log file. For unlimited retention, pass null. The default is 31.</param>
142
142
/// <param name="encoding">Character encoding used to write the text file. The default is UTF-8 without BOM.</param>
143
+ /// <param name="wrapper">Optionally enables wrapping the output stream in another stream, such as a GZipStream.</param>
143
144
/// <returns>Configuration object allowing method chaining.</returns>
144
145
/// <remarks>The file will be written using the UTF-8 character set.</remarks>
145
146
public static LoggerConfiguration File (
@@ -156,7 +157,8 @@ public static LoggerConfiguration File(
156
157
RollingInterval rollingInterval = RollingInterval . Infinite ,
157
158
bool rollOnFileSizeLimit = false ,
158
159
int ? retainedFileCountLimit = DefaultRetainedFileCountLimit ,
159
- Encoding encoding = null )
160
+ Encoding encoding = null ,
161
+ StreamWrapper wrapper = null )
160
162
{
161
163
if ( sinkConfiguration == null ) throw new ArgumentNullException ( nameof ( sinkConfiguration ) ) ;
162
164
if ( path == null ) throw new ArgumentNullException ( nameof ( path ) ) ;
@@ -165,7 +167,7 @@ public static LoggerConfiguration File(
165
167
var formatter = new MessageTemplateTextFormatter ( outputTemplate , formatProvider ) ;
166
168
return File ( sinkConfiguration , formatter , path , restrictedToMinimumLevel , fileSizeLimitBytes ,
167
169
levelSwitch , buffered , shared , flushToDiskInterval ,
168
- rollingInterval , rollOnFileSizeLimit , retainedFileCountLimit , encoding ) ;
170
+ rollingInterval , rollOnFileSizeLimit , retainedFileCountLimit , encoding , wrapper ) ;
169
171
}
170
172
171
173
/// <summary>
@@ -174,7 +176,7 @@ public static LoggerConfiguration File(
174
176
/// <param name="sinkConfiguration">Logger sink configuration.</param>
175
177
/// <param name="formatter">A formatter, such as <see cref="JsonFormatter"/>, to convert the log events into
176
178
/// text for the file. If control of regular text formatting is required, use the other
177
- /// overload of <see cref="File(LoggerSinkConfiguration, string, LogEventLevel, string, IFormatProvider, long?, LoggingLevelSwitch, bool, bool, TimeSpan?, RollingInterval, bool, int?, Encoding)"/>
179
+ /// overload of <see cref="File(LoggerSinkConfiguration, string, LogEventLevel, string, IFormatProvider, long?, LoggingLevelSwitch, bool, bool, TimeSpan?, RollingInterval, bool, int?, Encoding, StreamWrapper )"/>
178
180
/// and specify the outputTemplate parameter instead.
179
181
/// </param>
180
182
/// <param name="path">Path to the file.</param>
@@ -190,11 +192,12 @@ public static LoggerConfiguration File(
190
192
/// <param name="shared">Allow the log file to be shared by multiple processes. The default is false.</param>
191
193
/// <param name="flushToDiskInterval">If provided, a full disk flush will be performed periodically at the specified interval.</param>
192
194
/// <param name="rollingInterval">The interval at which logging will roll over to a new file.</param>
193
- /// <param name="rollOnFileSizeLimit">If <code>true</code>, a new file will be created when the file size limit is reached. Filenames
195
+ /// <param name="rollOnFileSizeLimit">If <code>true</code>, a new file will be created when the file size limit is reached. Filenames
194
196
/// will have a number appended in the format <code>_NNN</code>, with the first filename given no number.</param>
195
197
/// <param name="retainedFileCountLimit">The maximum number of log files that will be retained,
196
198
/// including the current log file. For unlimited retention, pass null. The default is 31.</param>
197
199
/// <param name="encoding">Character encoding used to write the text file. The default is UTF-8 without BOM.</param>
200
+ /// <param name="wrapper">Optionally enables wrapping the output stream in another stream, such as a GZipStream.</param>
198
201
/// <returns>Configuration object allowing method chaining.</returns>
199
202
/// <remarks>The file will be written using the UTF-8 character set.</remarks>
200
203
public static LoggerConfiguration File (
@@ -210,10 +213,12 @@ public static LoggerConfiguration File(
210
213
RollingInterval rollingInterval = RollingInterval . Infinite ,
211
214
bool rollOnFileSizeLimit = false ,
212
215
int ? retainedFileCountLimit = DefaultRetainedFileCountLimit ,
213
- Encoding encoding = null )
216
+ Encoding encoding = null ,
217
+ StreamWrapper wrapper = null )
214
218
{
215
219
return ConfigureFile ( sinkConfiguration . Sink , formatter , path , restrictedToMinimumLevel , fileSizeLimitBytes , levelSwitch ,
216
- buffered , false , shared , flushToDiskInterval , encoding , rollingInterval , rollOnFileSizeLimit , retainedFileCountLimit ) ;
220
+ buffered , false , shared , flushToDiskInterval , encoding , rollingInterval , rollOnFileSizeLimit ,
221
+ retainedFileCountLimit , wrapper ) ;
217
222
}
218
223
219
224
/// <summary>
@@ -270,7 +275,7 @@ public static LoggerConfiguration File(
270
275
LoggingLevelSwitch levelSwitch = null )
271
276
{
272
277
return ConfigureFile ( sinkConfiguration . Sink , formatter , path , restrictedToMinimumLevel , null , levelSwitch , false , true ,
273
- false , null , null , RollingInterval . Infinite , false , null ) ;
278
+ false , null , null , RollingInterval . Infinite , false , null , null ) ;
274
279
}
275
280
276
281
static LoggerConfiguration ConfigureFile (
@@ -287,7 +292,8 @@ static LoggerConfiguration ConfigureFile(
287
292
Encoding encoding ,
288
293
RollingInterval rollingInterval ,
289
294
bool rollOnFileSizeLimit ,
290
- int ? retainedFileCountLimit )
295
+ int ? retainedFileCountLimit ,
296
+ StreamWrapper wrapper )
291
297
{
292
298
if ( addSink == null ) throw new ArgumentNullException ( nameof ( addSink ) ) ;
293
299
if ( formatter == null ) throw new ArgumentNullException ( nameof ( formatter ) ) ;
@@ -300,7 +306,7 @@ static LoggerConfiguration ConfigureFile(
300
306
301
307
if ( rollOnFileSizeLimit || rollingInterval != RollingInterval . Infinite )
302
308
{
303
- sink = new RollingFileSink ( path , formatter , fileSizeLimitBytes , retainedFileCountLimit , encoding , buffered , shared , rollingInterval , rollOnFileSizeLimit ) ;
309
+ sink = new RollingFileSink ( path , formatter , fileSizeLimitBytes , retainedFileCountLimit , encoding , buffered , shared , rollingInterval , rollOnFileSizeLimit , wrapper ) ;
304
310
}
305
311
else
306
312
{
@@ -309,11 +315,16 @@ static LoggerConfiguration ConfigureFile(
309
315
#pragma warning disable 618
310
316
if ( shared )
311
317
{
318
+ if ( wrapper != null )
319
+ {
320
+ SelfLog . WriteLine ( "Unable to use output stream wrapper - these are not supported for shared log files" ) ;
321
+ }
322
+
312
323
sink = new SharedFileSink ( path , formatter , fileSizeLimitBytes ) ;
313
324
}
314
325
else
315
326
{
316
- sink = new FileSink ( path , formatter , fileSizeLimitBytes , buffered : buffered ) ;
327
+ sink = new FileSink ( path , formatter , fileSizeLimitBytes , buffered : buffered , wrapper : wrapper ) ;
317
328
}
318
329
#pragma warning restore 618
319
330
}
0 commit comments