From 4ed92a0447761d90c5738e50cb14a720e1d1dcc9 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Tue, 25 Oct 2016 10:50:24 +1000 Subject: [PATCH 1/4] Dev version bump [Skip CI] --- src/Serilog.Sinks.RollingFile/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.RollingFile/project.json b/src/Serilog.Sinks.RollingFile/project.json index 8c28070..4421033 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.2.1-*", "description": "The rolling file sink for Serilog - Simple .NET logging with fully-structured events", "authors": [ "Serilog Contributors" ], "packOptions": { From 1b35d8d989576956dc9132302cafe8e25d498f87 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Mon, 28 Nov 2016 08:57:22 +1000 Subject: [PATCH 2/4] Fixes #37 - sharing on .NET Core --- .../Sinks/RollingFile/RollingFileSink.cs | 9 ---- src/Serilog.Sinks.RollingFile/project.json | 4 +- .../RollingFileSinkTests.cs | 46 +++++++++++++++---- 3 files changed, 40 insertions(+), 19 deletions(-) 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 4421033..93b559f 100644 --- a/src/Serilog.Sinks.RollingFile/project.json +++ b/src/Serilog.Sinks.RollingFile/project.json @@ -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-dev-00762" }, "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); } } From 1f246b17214fc27c061bf7cb1ad07c1fc16419d5 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Thu, 1 Dec 2016 12:48:18 +1000 Subject: [PATCH 3/4] New functionality added; bumping minor version --- src/Serilog.Sinks.RollingFile/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.RollingFile/project.json b/src/Serilog.Sinks.RollingFile/project.json index 93b559f..38b79c8 100644 --- a/src/Serilog.Sinks.RollingFile/project.json +++ b/src/Serilog.Sinks.RollingFile/project.json @@ -1,5 +1,5 @@ { - "version": "3.2.1-*", + "version": "3.3.0-*", "description": "The rolling file sink for Serilog - Simple .NET logging with fully-structured events", "authors": [ "Serilog Contributors" ], "packOptions": { From 5a5ddb396d717c83087138330d8e4a8db0a592bc Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Tue, 3 Jan 2017 12:55:11 +1000 Subject: [PATCH 4/4] Update to the released version of Serilog.Sinks.File 3.2.0 --- src/Serilog.Sinks.RollingFile/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.RollingFile/project.json b/src/Serilog.Sinks.RollingFile/project.json index 38b79c8..cbfa6d4 100644 --- a/src/Serilog.Sinks.RollingFile/project.json +++ b/src/Serilog.Sinks.RollingFile/project.json @@ -9,7 +9,7 @@ "iconUrl": "http://serilog.net/images/serilog-sink-nuget.png" }, "dependencies": { - "Serilog.Sinks.File": "3.2.0-dev-00762" + "Serilog.Sinks.File": "3.2.0" }, "buildOptions": { "keyFile": "../../assets/Serilog.snk",