Skip to content

Commit 9eee731

Browse files
committed
Rename StreamWrapper to FileLifecycleHooks
1 parent f7bfe4e commit 9eee731

File tree

7 files changed

+30
-29
lines changed

7 files changed

+30
-29
lines changed

src/Serilog.Sinks.File/StreamWrapper.cs renamed to src/Serilog.Sinks.File/FileLifecycleHooks.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
using System.IO;
21

32
namespace Serilog
43
{
4+
using System.IO;
5+
56
/// <summary>
6-
/// Wraps the log file's output stream in another stream, such as a GZipStream
7+
/// Enables hooking into log file lifecycle events
78
/// </summary>
8-
public abstract class StreamWrapper
9+
public abstract class FileLifecycleHooks
910
{
1011
/// <summary>
1112
/// Wraps <paramref name="sourceStream"/> in another stream, such as a GZipStream, then returns the wrapped stream

src/Serilog.Sinks.File/FileLoggerConfigurationExtensions.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public static LoggerConfiguration File(
140140
/// <param name="retainedFileCountLimit">The maximum number of log files that will be retained,
141141
/// including the current log file. For unlimited retention, pass null. The default is 31.</param>
142142
/// <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+
/// <param name="hooks">Optionally enables hooking into log file lifecycle events.</param>
144144
/// <returns>Configuration object allowing method chaining.</returns>
145145
/// <remarks>The file will be written using the UTF-8 character set.</remarks>
146146
public static LoggerConfiguration File(
@@ -158,7 +158,7 @@ public static LoggerConfiguration File(
158158
bool rollOnFileSizeLimit = false,
159159
int? retainedFileCountLimit = DefaultRetainedFileCountLimit,
160160
Encoding encoding = null,
161-
StreamWrapper wrapper = null)
161+
FileLifecycleHooks hooks = null)
162162
{
163163
if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration));
164164
if (path == null) throw new ArgumentNullException(nameof(path));
@@ -167,7 +167,7 @@ public static LoggerConfiguration File(
167167
var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);
168168
return File(sinkConfiguration, formatter, path, restrictedToMinimumLevel, fileSizeLimitBytes,
169169
levelSwitch, buffered, shared, flushToDiskInterval,
170-
rollingInterval, rollOnFileSizeLimit, retainedFileCountLimit, encoding, wrapper);
170+
rollingInterval, rollOnFileSizeLimit, retainedFileCountLimit, encoding, hooks);
171171
}
172172

173173
/// <summary>
@@ -176,7 +176,7 @@ public static LoggerConfiguration File(
176176
/// <param name="sinkConfiguration">Logger sink configuration.</param>
177177
/// <param name="formatter">A formatter, such as <see cref="JsonFormatter"/>, to convert the log events into
178178
/// text for the file. If control of regular text formatting is required, use the other
179-
/// overload of <see cref="File(LoggerSinkConfiguration, string, LogEventLevel, string, IFormatProvider, long?, LoggingLevelSwitch, bool, bool, TimeSpan?, RollingInterval, bool, int?, Encoding, StreamWrapper)"/>
179+
/// overload of <see cref="File(LoggerSinkConfiguration, string, LogEventLevel, string, IFormatProvider, long?, LoggingLevelSwitch, bool, bool, TimeSpan?, RollingInterval, bool, int?, Encoding, FileLifecycleHooks)"/>
180180
/// and specify the outputTemplate parameter instead.
181181
/// </param>
182182
/// <param name="path">Path to the file.</param>
@@ -197,7 +197,7 @@ public static LoggerConfiguration File(
197197
/// <param name="retainedFileCountLimit">The maximum number of log files that will be retained,
198198
/// including the current log file. For unlimited retention, pass null. The default is 31.</param>
199199
/// <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>
200+
/// <param name="hooks">Optionally enables hooking into log file lifecycle events.</param>
201201
/// <returns>Configuration object allowing method chaining.</returns>
202202
/// <remarks>The file will be written using the UTF-8 character set.</remarks>
203203
public static LoggerConfiguration File(
@@ -214,11 +214,11 @@ public static LoggerConfiguration File(
214214
bool rollOnFileSizeLimit = false,
215215
int? retainedFileCountLimit = DefaultRetainedFileCountLimit,
216216
Encoding encoding = null,
217-
StreamWrapper wrapper = null)
217+
FileLifecycleHooks hooks = null)
218218
{
219219
return ConfigureFile(sinkConfiguration.Sink, formatter, path, restrictedToMinimumLevel, fileSizeLimitBytes, levelSwitch,
220220
buffered, false, shared, flushToDiskInterval, encoding, rollingInterval, rollOnFileSizeLimit,
221-
retainedFileCountLimit, wrapper);
221+
retainedFileCountLimit, hooks);
222222
}
223223

224224
/// <summary>
@@ -293,7 +293,7 @@ static LoggerConfiguration ConfigureFile(
293293
RollingInterval rollingInterval,
294294
bool rollOnFileSizeLimit,
295295
int? retainedFileCountLimit,
296-
StreamWrapper wrapper)
296+
FileLifecycleHooks hooks)
297297
{
298298
if (addSink == null) throw new ArgumentNullException(nameof(addSink));
299299
if (formatter == null) throw new ArgumentNullException(nameof(formatter));
@@ -306,7 +306,7 @@ static LoggerConfiguration ConfigureFile(
306306

307307
if (rollOnFileSizeLimit || rollingInterval != RollingInterval.Infinite)
308308
{
309-
sink = new RollingFileSink(path, formatter, fileSizeLimitBytes, retainedFileCountLimit, encoding, buffered, shared, rollingInterval, rollOnFileSizeLimit, wrapper);
309+
sink = new RollingFileSink(path, formatter, fileSizeLimitBytes, retainedFileCountLimit, encoding, buffered, shared, rollingInterval, rollOnFileSizeLimit, hooks);
310310
}
311311
else
312312
{
@@ -315,7 +315,7 @@ static LoggerConfiguration ConfigureFile(
315315
#pragma warning disable 618
316316
if (shared)
317317
{
318-
if (wrapper != null)
318+
if (hooks != null)
319319
{
320320
SelfLog.WriteLine("Unable to use output stream wrapper - these are not supported for shared log files");
321321
}
@@ -324,7 +324,7 @@ static LoggerConfiguration ConfigureFile(
324324
}
325325
else
326326
{
327-
sink = new FileSink(path, formatter, fileSizeLimitBytes, buffered: buffered, wrapper: wrapper);
327+
sink = new FileSink(path, formatter, fileSizeLimitBytes, buffered: buffered, hooks: hooks);
328328
}
329329
#pragma warning restore 618
330330
}

src/Serilog.Sinks.File/Sinks/File/FileSink.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ public sealed class FileSink : IFileSink, IDisposable
4343
/// <param name="encoding">Character encoding used to write the text file. The default is UTF-8 without BOM.</param>
4444
/// <param name="buffered">Indicates if flushing to the output file can be buffered or not. The default
4545
/// is false.</param>
46-
/// <param name="wrapper">Optionally enables wrapping the output stream in another stream, such as a GZipStream.</param>
46+
/// <param name="hooks">Optionally enables hooking into log file lifecycle events.</param>
4747
/// <returns>Configuration object allowing method chaining.</returns>
4848
/// <remarks>The file will be written using the UTF-8 character set.</remarks>
4949
/// <exception cref="IOException"></exception>
5050
public FileSink(string path, ITextFormatter textFormatter, long? fileSizeLimitBytes, Encoding encoding = null, bool buffered = false,
51-
StreamWrapper wrapper = null)
51+
FileLifecycleHooks hooks = null)
5252
{
5353
if (path == null) throw new ArgumentNullException(nameof(path));
5454
if (textFormatter == null) throw new ArgumentNullException(nameof(textFormatter));
@@ -70,9 +70,9 @@ public FileSink(string path, ITextFormatter textFormatter, long? fileSizeLimitBy
7070
outputStream = _countingStreamWrapper = new WriteCountingStream(_underlyingStream);
7171
}
7272

73-
if (wrapper != null)
73+
if (hooks != null)
7474
{
75-
outputStream = wrapper.Wrap(outputStream);
75+
outputStream = hooks.Wrap(outputStream);
7676
}
7777

7878
_output = new StreamWriter(outputStream, encoding ?? new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));

src/Serilog.Sinks.File/Sinks/File/RollingFileSink.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ sealed class RollingFileSink : ILogEventSink, IFlushableFileSink, IDisposable
3535
readonly bool _buffered;
3636
readonly bool _shared;
3737
readonly bool _rollOnFileSizeLimit;
38-
readonly StreamWrapper _wrapper;
38+
readonly FileLifecycleHooks _hooks;
3939

4040
readonly object _syncRoot = new object();
4141
bool _isDisposed;
@@ -52,7 +52,7 @@ public RollingFileSink(string path,
5252
bool shared,
5353
RollingInterval rollingInterval,
5454
bool rollOnFileSizeLimit,
55-
StreamWrapper wrapper = null)
55+
FileLifecycleHooks hooks = null)
5656
{
5757
if (path == null) throw new ArgumentNullException(nameof(path));
5858
if (fileSizeLimitBytes.HasValue && fileSizeLimitBytes < 0) throw new ArgumentException("Negative value provided; file size limit must be non-negative");
@@ -66,7 +66,7 @@ public RollingFileSink(string path,
6666
_buffered = buffered;
6767
_shared = shared;
6868
_rollOnFileSizeLimit = rollOnFileSizeLimit;
69-
_wrapper = wrapper;
69+
_hooks = hooks;
7070
}
7171

7272
public void Emit(LogEvent logEvent)
@@ -147,7 +147,7 @@ void OpenFile(DateTime now, int? minSequence = null)
147147
{
148148
_currentFile = _shared ?
149149
(IFileSink)new SharedFileSink(path, _textFormatter, _fileSizeLimitBytes, _encoding) :
150-
new FileSink(path, _textFormatter, _fileSizeLimitBytes, _encoding, _buffered, _wrapper);
150+
new FileSink(path, _textFormatter, _fileSizeLimitBytes, _encoding, _buffered, _hooks);
151151
_currentFileSequence = sequence;
152152
}
153153
catch (IOException ex)

test/Serilog.Sinks.File.Tests/FileSinkTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,14 @@ public void WhenLimitIsNotSpecifiedAndEncodingHasNoPreambleDataIsCorrectlyAppend
146146
[Fact]
147147
public void WhenStreamWrapperIsSpecifiedOutputStreamIsWrapped()
148148
{
149-
var gzipWrapper = new GZipStreamWrapper();
149+
var gzipWrapper = new GZipHooks();
150150

151151
using (var tmp = TempFolder.ForCaller())
152152
{
153153
var nonexistent = tmp.AllocateFilename("txt");
154154
var evt = Some.LogEvent("Hello, world!");
155155

156-
using (var sink = new FileSink(nonexistent, new JsonFormatter(), null, wrapper: gzipWrapper))
156+
using (var sink = new FileSink(nonexistent, new JsonFormatter(), null, hooks: gzipWrapper))
157157
{
158158
sink.Emit(evt);
159159
sink.Emit(evt);

test/Serilog.Sinks.File.Tests/RollingFileSinkTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void WhenSizeLimitIsBreachedNewFilesCreated()
100100
[Fact]
101101
public void WhenStreamWrapperSpecifiedIsUsedForRolledFiles()
102102
{
103-
var gzipWrapper = new GZipStreamWrapper();
103+
var gzipWrapper = new GZipHooks();
104104
var fileName = Some.String() + ".txt";
105105

106106
using (var temp = new TempFolder())
@@ -114,7 +114,7 @@ public void WhenStreamWrapperSpecifiedIsUsedForRolledFiles()
114114
};
115115

116116
using (var log = new LoggerConfiguration()
117-
.WriteTo.File(Path.Combine(temp.Path, fileName), rollOnFileSizeLimit: true, fileSizeLimitBytes: 1, wrapper: gzipWrapper)
117+
.WriteTo.File(Path.Combine(temp.Path, fileName), rollOnFileSizeLimit: true, fileSizeLimitBytes: 1, hooks: gzipWrapper)
118118
.CreateLogger())
119119
{
120120

test/Serilog.Sinks.File.Tests/Support/GZipStreamWrapper.cs renamed to test/Serilog.Sinks.File.Tests/Support/GZipHooks.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ namespace Serilog.Sinks.File.Tests.Support
55
{
66
/// <inheritdoc />
77
/// <summary>
8-
/// Demonstrates the use of <seealso cref="T:Serilog.StreamWrapper" />, by compressing log output using GZip
8+
/// Demonstrates the use of <seealso cref="T:Serilog.FileLifecycleHooks" />, by compressing log output using GZip
99
/// </summary>
10-
public class GZipStreamWrapper : StreamWrapper
10+
public class GZipHooks : FileLifecycleHooks
1111
{
1212
readonly int _bufferSize;
1313

14-
public GZipStreamWrapper(int bufferSize = 1024 * 32)
14+
public GZipHooks(int bufferSize = 1024 * 32)
1515
{
1616
_bufferSize = bufferSize;
1717
}

0 commit comments

Comments
 (0)