diff --git a/src/Serilog.Sinks.RollingFile/Sinks/RollingFile/RollingFileSink.cs b/src/Serilog.Sinks.RollingFile/Sinks/RollingFile/RollingFileSink.cs index 7a735f1..d7f8d6d 100644 --- a/src/Serilog.Sinks.RollingFile/Sinks/RollingFile/RollingFileSink.cs +++ b/src/Serilog.Sinks.RollingFile/Sinks/RollingFile/RollingFileSink.cs @@ -71,11 +71,6 @@ public RollingFileSink(string pathFormat, if (fileSizeLimitBytes.HasValue && fileSizeLimitBytes < 0) throw new ArgumentException("Negative value provided; file size limit must be non-negative"); if (retainedFileCountLimit.HasValue && retainedFileCountLimit < 1) throw new ArgumentException("Zero or negative value provided; retained file count limit must be at least 1"); -#if !SHARING - if (shared) - throw new NotSupportedException("File sharing is not supported on this platform."); -#endif - _roller = new TemplatedPathRoller(pathFormat); _textFormatter = textFormatter; _fileSizeLimitBytes = fileSizeLimitBytes; @@ -154,13 +149,9 @@ void OpenFile(DateTime now) try { -#if SHARING _currentFile = _shared ? (ILogEventSink)new SharedFileSink(path, _textFormatter, _fileSizeLimitBytes, _encoding) : new FileSink(path, _textFormatter, _fileSizeLimitBytes, _encoding, _buffered); -#else - _currentFile = new FileSink(path, _textFormatter, _fileSizeLimitBytes, _encoding, _buffered); -#endif } catch (IOException ex) { diff --git a/src/Serilog.Sinks.RollingFile/project.json b/src/Serilog.Sinks.RollingFile/project.json index 8c28070..cbfa6d4 100644 --- a/src/Serilog.Sinks.RollingFile/project.json +++ b/src/Serilog.Sinks.RollingFile/project.json @@ -1,5 +1,5 @@ { - "version": "3.2.0-*", + "version": "3.3.0-*", "description": "The rolling file sink for Serilog - Simple .NET logging with fully-structured events", "authors": [ "Serilog Contributors" ], "packOptions": { @@ -9,7 +9,7 @@ "iconUrl": "http://serilog.net/images/serilog-sink-nuget.png" }, "dependencies": { - "Serilog.Sinks.File": "3.1.0" + "Serilog.Sinks.File": "3.2.0" }, "buildOptions": { "keyFile": "../../assets/Serilog.snk", @@ -18,7 +18,7 @@ }, "frameworks": { "net4.5": { - "buildOptions": {"define": ["SHARING", "HRESULTS"]} + "buildOptions": {"define": ["HRESULTS"]} }, "netstandard1.3": { "dependencies": { diff --git a/test/Serilog.Sinks.RollingFile.Tests/RollingFileSinkTests.cs b/test/Serilog.Sinks.RollingFile.Tests/RollingFileSinkTests.cs index 4fca4b8..d1f25c2 100644 --- a/test/Serilog.Sinks.RollingFile.Tests/RollingFileSinkTests.cs +++ b/test/Serilog.Sinks.RollingFile.Tests/RollingFileSinkTests.cs @@ -4,6 +4,7 @@ using Xunit; using Serilog.Events; using Serilog.Sinks.RollingFile.Tests.Support; +using Serilog.Configuration; namespace Serilog.Sinks.RollingFile.Tests { @@ -15,6 +16,31 @@ public void LogEventsAreEmittedToTheFileNamedAccordingToTheEventTimestamp() TestRollingEventSequence(Some.InformationEvent()); } + [Fact] + public void EventsAreWrittenWhenSharingIsEnabled() + { + TestRollingEventSequence( + (pf, wt) => wt.RollingFile(pf, shared: true), + new[] { Some.InformationEvent() }); + } + + [Fact] + public void EventsAreWrittenWhenBufferingIsEnabled() + { + TestRollingEventSequence( + (pf, wt) => wt.RollingFile(pf, buffered: true), + new[] { Some.InformationEvent() }); + } + + [Fact] + public void EventsAreWrittenWhenDiskFlushingIsEnabled() + { + // Doesn't test flushing, but ensures we haven't broken basic logging + TestRollingEventSequence( + (pf, wt) => wt.RollingFile(pf, flushToDiskInterval: TimeSpan.FromMilliseconds(50)), + new[] { Some.InformationEvent() }); + } + [Fact] public void WhenTheDateChangesTheCorrectFileIsWritten() { @@ -30,7 +56,9 @@ public void WhenRetentionCountIsSetOldFilesAreDeleted() e2 = Some.InformationEvent(e1.Timestamp.AddDays(1)), e3 = Some.InformationEvent(e2.Timestamp.AddDays(5)); - TestRollingEventSequence(new[] { e1, e2, e3 }, 2, + TestRollingEventSequence( + (pf, wt) => wt.RollingFile(pf, retainedFileCountLimit: 2), + new[] { e1, e2, e3 }, files => { Assert.Equal(3, files.Count); @@ -70,21 +98,23 @@ public void IfTheLogFolderDoesNotExistItWillBeCreated() static void TestRollingEventSequence(params LogEvent[] events) { - TestRollingEventSequence(events, null, f => {}); + TestRollingEventSequence( + (pf, wt) => wt.RollingFile(pf, retainedFileCountLimit: null), + events); } static void TestRollingEventSequence( + Action configureFile, IEnumerable events, - int? retainedFiles, - Action> verifyWritten) + Action> verifyWritten = null) { var fileName = Some.String() + "-{Date}.txt"; var folder = Some.TempFolderPath(); var pathFormat = Path.Combine(folder, fileName); - var log = new LoggerConfiguration() - .WriteTo.RollingFile(pathFormat, retainedFileCountLimit: retainedFiles) - .CreateLogger(); + var config = new LoggerConfiguration(); + configureFile(pathFormat, config.WriteTo); + var log = config.CreateLogger(); var verified = new List(); @@ -104,7 +134,7 @@ static void TestRollingEventSequence( finally { log.Dispose(); - verifyWritten(verified); + verifyWritten?.Invoke(verified); Directory.Delete(folder, true); } }