Skip to content

Commit

Permalink
Merge pull request #41 from serilog/dev
Browse files Browse the repository at this point in the history
3.3.0 Release
  • Loading branch information
nblumhardt authored Jan 3, 2017
2 parents 983fb02 + 5a5ddb3 commit 2a24d25
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Serilog.Sinks.RollingFile/project.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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",
Expand All @@ -18,7 +18,7 @@
},
"frameworks": {
"net4.5": {
"buildOptions": {"define": ["SHARING", "HRESULTS"]}
"buildOptions": {"define": ["HRESULTS"]}
},
"netstandard1.3": {
"dependencies": {
Expand Down
46 changes: 38 additions & 8 deletions test/Serilog.Sinks.RollingFile.Tests/RollingFileSinkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Xunit;
using Serilog.Events;
using Serilog.Sinks.RollingFile.Tests.Support;
using Serilog.Configuration;

namespace Serilog.Sinks.RollingFile.Tests
{
Expand All @@ -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()
{
Expand All @@ -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);
Expand Down Expand Up @@ -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<string, LoggerSinkConfiguration> configureFile,
IEnumerable<LogEvent> events,
int? retainedFiles,
Action<IList<string>> verifyWritten)
Action<IList<string>> 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<string>();

Expand All @@ -104,7 +134,7 @@ static void TestRollingEventSequence(
finally
{
log.Dispose();
verifyWritten(verified);
verifyWritten?.Invoke(verified);
Directory.Delete(folder, true);
}
}
Expand Down

0 comments on commit 2a24d25

Please sign in to comment.