-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FileTarget - Archive should not fail when ArchiveFileName matches FileName #1886
FileTarget - Archive should not fail when ArchiveFileName matches FileName #1886
Conversation
Great work! \o/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change of test still needed?
Well the test is not depending on FileArchivePeriod.Minutes, so no need to introduce more random behavior than needed. Added a new test that exercises the new code. |
ffd7882
to
5fdc97e
Compare
Current coverage is 81% (diff: 100%)@@ master #1886 diff @@
==========================================
Files 276 276
Lines 18636 18640 +4
Methods 2861 2861
Messages 0 0
Branches 2139 2140 +1
==========================================
- Hits 15160 15157 -3
- Misses 2971 2978 +7
Partials 505 505
|
Reviewed 2 of 2 files at r1. Comments from Reviewable |
merged :) |
So is the warning still valid: |
No this was fixed with NLog 4.5, but for NLog 4.4.13 (or older) then the advice is still valid.
|
@owerkop Have updated the Wiki for FileTarget about warning only being relevant for NLog 4.4.13 (and older) |
Looks great @snakefoot , thanks! (And valid question @owerkop. Also thanks for that!) |
Attempt to fix the following build error, and also resolve this issue #1707
https://ci.appveyor.com/project/nlog/nlog/build/4.4.4171
Was able to reproduce the bug locally, and it seems the following happens:
The test uses ArchiveEvery = FileArchivePeriod.Minute and FileName = ${date:format=yyyyMMddHHmmssfff}.txt. It sleeps 50 ms between each LogEvent to ensure that each LogEvent get their own file.
If the test is executed at exact 12:59:59.999 then it will trigger an extra unexpected archive operation. As one of LogEvent timestamps will then be one-minute older than the creation-time of the previous log-file.
The archive operation fails because the log-filename (based on current-time) and the generated archive-filename (based on file-write-time) becomes the same. Because the archive-filename already exists then it attempts to append the contents of the log-filename to the archive-filename and it of course fails.
We could change the ArchiveEvery to Year for the test DeleteArchiveFilesByDateWithDateName, and then it would only fail at new years eve.
We could also consider to change FileTarget.ArchiveFile() to check if fileName and archiveFileName is the same, and if so then just do nothing but doing a InternalLogger.Info()
This change is