-
Notifications
You must be signed in to change notification settings - Fork 125
File retention policy by date/time #90
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
Conversation
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.
Sorry about the slow response, here! Thanks for taking the time to send this.
It seems like a nice, clean, change; there's a bit to digest. I can see how there could be some 'jitter' around the roll points if events are logged out-of-order and there's a very short/zero retention time; this issue is present with very small rolling sets, too, though.
One glitch is that if the app stops logging, the policy will not be triggered and the old files will be kept - may not be a major problem (the same thing occurs if the app is shut down :-)) but worth considering, perhaps with a note.
If you're keen to push ahead with this one, it'd be great also to include a couple of tests that exercise it.
Thanks again!
Thanks a lot for your review @nblumhardt |
@nblumhardt, thanks again for the review and suggestions. I pushed the new code including your suggestions, but I just noticed that I didn't updated my forked code with the new |
Update Fork
Just rebased my changes onto the upstream, fixed conflicts and ran unit and manual tests here. |
…der than X time Fixed constructors for compatibility; Unified where clause to retain files Adjust error messages New test cases
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.
Looking great! Thanks for the update, sorry it's taken so long to get some eyes on this.
Had a couple of points to consider - should be getting down to the last of it now :-)
.Where(n => StringComparer.OrdinalIgnoreCase.Compare(currentFileName, n) != 0) | ||
.Skip(_retainedFileCountLimit.Value - 1) | ||
.Where(n => StringComparer.OrdinalIgnoreCase.Compare(currentFileName, n.Filename) != 0) | ||
.SkipWhile((x, i) => (i < (_retainedFileCountLimit - 1 ?? 0)) && |
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.
The default of 0
for a null _retainedFileCountLimit
seems wrong here, since i
will never be less than it (null
is intended to indicate "no limit").
Could pulling this expression out into a local function (with some locals, or structured return (true|false)
make the logic a bit clearer?
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.
I put 0
there, thinking that if retainedFileCountLimit
got there as null, then I'll ignore this condition. Do you think maybe 31
(the default value) would be better instead (in case of null
)?
I'll extract a function to get this piece of code clearer. I also didn't really like it the way it is.
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.
I think it'll be hard to get the logic right here without checking retainedFileCountLimit
against null, but guessing this will all come out more clearly with some reorganisation :-)
No worries =) |
@nblumhardt I was able to push the requested changes. If there's anything else, please, let me know and I'll correct right away. I did give some thoughts on that |
Just wondered if there is any update on getting this PR merged? |
Thanks for the nudge, @iamandymcinnes - I'm keen to merge this PR, I need to sanity check myself before pushing the button (there's a binary breaking change which might necessitate downstream changes, too), I'll try to loop back around ASAP, if no one else beats me to it :-) |
Same question as @iamandymcinnes, what is the status of this PR? |
Bump. The file-count-only stock retention policy for files is very limiting. Services / programs that restart many times in a short period of time (and create a new file each time without log sharing) run the risk of losing logs. There is probably further consideration on how to handle 'groups of' log files in general, including PID/AppDomain-time distinction to avoid shared files. |
@pnstickne @ericvb thanks for the bump; sorry again about the delay, @thiagosgarcia - I'll get there! 😅 Paul, check out https://github.com/serilog/serilog-sinks-map as one way to address the file-set-per-PID type scenarios (assuming you've tried and ruled out passing |
@thiagosgarcia Thank you for your effort to include this as a feature. @nblumhardt Any update on this PR? Any expected time when it will be closed? |
Fixed my test breakage locally on the way through the works :-) |
Out in the 5.0-dev build 🎉 - thanks @thiagosgarcia :-) |
Thank you @nblumhardt! If there's anything else I can do, please let me know =) |
Hello, |
@thiagosgarcia @nblumhardt |
@abrasat per https://www.nuget.org/packages/serilog.sinks.file it is released. If you're having trouble configuring it, the best thing to do is to raise an issue on stackoverflow.com tagged |
Hello, |
Add configuration to discard files older than X time defined by a TimeSpan variable.
As discussed in issue #39, I think (and it did work for me) that would be nice to have a dateTime-driven file retention policy.
There are some security policies that, for example, demands that all log files should be wiped after a few days or weeks. At the same time, you can have as much as possible data in logs, so, for some cases, the strongest rule for deleting log files would be date, not file count or size.
In the example below, files older than 7 days are deleted by
RollingFileSink.ApplyRetentionPolicy(_)
at a maximum count of 100 files, rolling by day or at a limit of 50MB per file