Skip to content

Commit 2a24d25

Browse files
authored
Merge pull request #41 from serilog/dev
3.3.0 Release
2 parents 983fb02 + 5a5ddb3 commit 2a24d25

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

Diff for: src/Serilog.Sinks.RollingFile/Sinks/RollingFile/RollingFileSink.cs

-9
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ public RollingFileSink(string pathFormat,
7171
if (fileSizeLimitBytes.HasValue && fileSizeLimitBytes < 0) throw new ArgumentException("Negative value provided; file size limit must be non-negative");
7272
if (retainedFileCountLimit.HasValue && retainedFileCountLimit < 1) throw new ArgumentException("Zero or negative value provided; retained file count limit must be at least 1");
7373

74-
#if !SHARING
75-
if (shared)
76-
throw new NotSupportedException("File sharing is not supported on this platform.");
77-
#endif
78-
7974
_roller = new TemplatedPathRoller(pathFormat);
8075
_textFormatter = textFormatter;
8176
_fileSizeLimitBytes = fileSizeLimitBytes;
@@ -154,13 +149,9 @@ void OpenFile(DateTime now)
154149

155150
try
156151
{
157-
#if SHARING
158152
_currentFile = _shared ?
159153
(ILogEventSink)new SharedFileSink(path, _textFormatter, _fileSizeLimitBytes, _encoding) :
160154
new FileSink(path, _textFormatter, _fileSizeLimitBytes, _encoding, _buffered);
161-
#else
162-
_currentFile = new FileSink(path, _textFormatter, _fileSizeLimitBytes, _encoding, _buffered);
163-
#endif
164155
}
165156
catch (IOException ex)
166157
{

Diff for: src/Serilog.Sinks.RollingFile/project.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "3.2.0-*",
2+
"version": "3.3.0-*",
33
"description": "The rolling file sink for Serilog - Simple .NET logging with fully-structured events",
44
"authors": [ "Serilog Contributors" ],
55
"packOptions": {
@@ -9,7 +9,7 @@
99
"iconUrl": "http://serilog.net/images/serilog-sink-nuget.png"
1010
},
1111
"dependencies": {
12-
"Serilog.Sinks.File": "3.1.0"
12+
"Serilog.Sinks.File": "3.2.0"
1313
},
1414
"buildOptions": {
1515
"keyFile": "../../assets/Serilog.snk",
@@ -18,7 +18,7 @@
1818
},
1919
"frameworks": {
2020
"net4.5": {
21-
"buildOptions": {"define": ["SHARING", "HRESULTS"]}
21+
"buildOptions": {"define": ["HRESULTS"]}
2222
},
2323
"netstandard1.3": {
2424
"dependencies": {

Diff for: test/Serilog.Sinks.RollingFile.Tests/RollingFileSinkTests.cs

+38-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Xunit;
55
using Serilog.Events;
66
using Serilog.Sinks.RollingFile.Tests.Support;
7+
using Serilog.Configuration;
78

89
namespace Serilog.Sinks.RollingFile.Tests
910
{
@@ -15,6 +16,31 @@ public void LogEventsAreEmittedToTheFileNamedAccordingToTheEventTimestamp()
1516
TestRollingEventSequence(Some.InformationEvent());
1617
}
1718

19+
[Fact]
20+
public void EventsAreWrittenWhenSharingIsEnabled()
21+
{
22+
TestRollingEventSequence(
23+
(pf, wt) => wt.RollingFile(pf, shared: true),
24+
new[] { Some.InformationEvent() });
25+
}
26+
27+
[Fact]
28+
public void EventsAreWrittenWhenBufferingIsEnabled()
29+
{
30+
TestRollingEventSequence(
31+
(pf, wt) => wt.RollingFile(pf, buffered: true),
32+
new[] { Some.InformationEvent() });
33+
}
34+
35+
[Fact]
36+
public void EventsAreWrittenWhenDiskFlushingIsEnabled()
37+
{
38+
// Doesn't test flushing, but ensures we haven't broken basic logging
39+
TestRollingEventSequence(
40+
(pf, wt) => wt.RollingFile(pf, flushToDiskInterval: TimeSpan.FromMilliseconds(50)),
41+
new[] { Some.InformationEvent() });
42+
}
43+
1844
[Fact]
1945
public void WhenTheDateChangesTheCorrectFileIsWritten()
2046
{
@@ -30,7 +56,9 @@ public void WhenRetentionCountIsSetOldFilesAreDeleted()
3056
e2 = Some.InformationEvent(e1.Timestamp.AddDays(1)),
3157
e3 = Some.InformationEvent(e2.Timestamp.AddDays(5));
3258

33-
TestRollingEventSequence(new[] { e1, e2, e3 }, 2,
59+
TestRollingEventSequence(
60+
(pf, wt) => wt.RollingFile(pf, retainedFileCountLimit: 2),
61+
new[] { e1, e2, e3 },
3462
files =>
3563
{
3664
Assert.Equal(3, files.Count);
@@ -70,21 +98,23 @@ public void IfTheLogFolderDoesNotExistItWillBeCreated()
7098

7199
static void TestRollingEventSequence(params LogEvent[] events)
72100
{
73-
TestRollingEventSequence(events, null, f => {});
101+
TestRollingEventSequence(
102+
(pf, wt) => wt.RollingFile(pf, retainedFileCountLimit: null),
103+
events);
74104
}
75105

76106
static void TestRollingEventSequence(
107+
Action<string, LoggerSinkConfiguration> configureFile,
77108
IEnumerable<LogEvent> events,
78-
int? retainedFiles,
79-
Action<IList<string>> verifyWritten)
109+
Action<IList<string>> verifyWritten = null)
80110
{
81111
var fileName = Some.String() + "-{Date}.txt";
82112
var folder = Some.TempFolderPath();
83113
var pathFormat = Path.Combine(folder, fileName);
84114

85-
var log = new LoggerConfiguration()
86-
.WriteTo.RollingFile(pathFormat, retainedFileCountLimit: retainedFiles)
87-
.CreateLogger();
115+
var config = new LoggerConfiguration();
116+
configureFile(pathFormat, config.WriteTo);
117+
var log = config.CreateLogger();
88118

89119
var verified = new List<string>();
90120

@@ -104,7 +134,7 @@ static void TestRollingEventSequence(
104134
finally
105135
{
106136
log.Dispose();
107-
verifyWritten(verified);
137+
verifyWritten?.Invoke(verified);
108138
Directory.Delete(folder, true);
109139
}
110140
}

0 commit comments

Comments
 (0)