Skip to content

Commit e310ab9

Browse files
committed
Throw when using hooks with a shared file
1 parent 873f6d4 commit e310ab9

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/Serilog.Sinks.File/FileLoggerConfigurationExtensions.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ static LoggerConfiguration ConfigureFile(
301301
if (fileSizeLimitBytes.HasValue && fileSizeLimitBytes < 0) throw new ArgumentException("Negative value provided; file size limit must be non-negative.", nameof(fileSizeLimitBytes));
302302
if (retainedFileCountLimit.HasValue && retainedFileCountLimit < 1) throw new ArgumentException("At least one file must be retained.", nameof(retainedFileCountLimit));
303303
if (shared && buffered) throw new ArgumentException("Buffered writes are not available when file sharing is enabled.", nameof(buffered));
304+
if (shared && hooks != null) throw new ArgumentException("Unable to use {hooks.GetType().Name} FileLifecycleHooks output stream wrapper - these are not supported for shared log files", nameof(hooks));
304305

305306
ILogEventSink sink;
306307

@@ -315,11 +316,6 @@ static LoggerConfiguration ConfigureFile(
315316
#pragma warning disable 618
316317
if (shared)
317318
{
318-
if (hooks != null)
319-
{
320-
SelfLog.WriteLine($"Unable to use {hooks.GetType().Name} FileLifecycleHooks output stream wrapper - these are not supported for shared log files");
321-
}
322-
323319
sink = new SharedFileSink(path, formatter, fileSizeLimitBytes);
324320
}
325321
else

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Threading;
33
using Serilog.Sinks.File.Tests.Support;
44
using Serilog.Tests.Support;
@@ -80,11 +80,11 @@ public void WhenFlushingToDiskReportedSharedFileSinkCanBeCreatedAndDisposed()
8080
}
8181

8282
[Fact]
83-
public void BufferingIsNotAvailableWhenSharingEnabled()
83+
public void HooksAreNotAvailableWhenSharingEnabled()
8484
{
8585
Assert.Throws<ArgumentException>(() =>
8686
new LoggerConfiguration()
87-
.WriteTo.File("logs", buffered: true, shared: true));
87+
.WriteTo.File("logs", shared: true, hooks: new GZipHooks()));
8888
}
8989
}
9090
}

0 commit comments

Comments
 (0)