From 146ef488ec77fc69bfcb1091a150077d407c0ecf Mon Sep 17 00:00:00 2001 From: Miguel Alho Date: Mon, 9 Oct 2017 15:45:16 +0100 Subject: [PATCH] fix bookmark advance (#27) One of the scenarios was not moving the bookmark to the next file I'm merging this one into dev to get a package to test . Should have correct behaviour based on observations --- .../Sinks/Loggly/FileBufferDataProvider.cs | 5 ++++- .../Sinks/Loggly/FileBufferDataProviderTests.cs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Serilog.Sinks.Loggly/Sinks/Loggly/FileBufferDataProvider.cs b/src/Serilog.Sinks.Loggly/Sinks/Loggly/FileBufferDataProvider.cs index 6556d16..8a5f39a 100644 --- a/src/Serilog.Sinks.Loggly/Sinks/Loggly/FileBufferDataProvider.cs +++ b/src/Serilog.Sinks.Loggly/Sinks/Loggly/FileBufferDataProvider.cs @@ -129,6 +129,7 @@ public void MoveBookmarkForward() { //move to next file _currentBookmark = new FileSetPosition(0, fileSet[1]); + _bookmarkProvider.UpdateBookmark(_currentBookmark); //we can also delete the previously read file since we no longer need it _fileSystemAdapter.DeleteFile(fileSet[0]); } @@ -145,8 +146,9 @@ public void MoveBookmarkForward() { //move to first file within retention limite _currentBookmark = _retainedFileCountLimit.Value >= fileSet.Length - ? new FileSetPosition(0, fileSet[0]) + ? new FileSetPosition(0, fileSet[1]) : new FileSetPosition(0, fileSet[fileSet.Length - _retainedFileCountLimit.Value]); + _bookmarkProvider.UpdateBookmark(_currentBookmark); //delete all the old files foreach (var oldFile in fileSet.Take(fileSet.Length - _retainedFileCountLimit.Value)) @@ -158,6 +160,7 @@ public void MoveBookmarkForward() { //move to the next file and delete the current one _currentBookmark = new FileSetPosition(0, fileSet[1]); + _bookmarkProvider.UpdateBookmark(_currentBookmark); //set the file bookmark to avoid _fileSystemAdapter.DeleteFile(fileSet[0]); } } diff --git a/test/Serilog.Sinks.Loggly.Tests/Sinks/Loggly/FileBufferDataProviderTests.cs b/test/Serilog.Sinks.Loggly.Tests/Sinks/Loggly/FileBufferDataProviderTests.cs index 60f1e45..aee61ee 100644 --- a/test/Serilog.Sinks.Loggly.Tests/Sinks/Loggly/FileBufferDataProviderTests.cs +++ b/test/Serilog.Sinks.Loggly.Tests/Sinks/Loggly/FileBufferDataProviderTests.cs @@ -696,7 +696,7 @@ IFileSystemAdapter CreateFileSystemAdapter() public void BookmarkShouldBeAtStartOfNextFile() => Assert.Equal(0, _sut.NextLineStart); [Fact] - public void BookmarkShouldBeAtNextFile() => Assert.Equal(@"c:\a\file001.json", _sut.File); + public void BookmarkShouldBeAtNextFile() => Assert.Equal(@"c:\a\file002.json", _sut.File); [Fact] public void NoFilesShouldHaveBeenDeleted() => Assert.Empty(_deletedFiles);