Closed dernippel closed 5 months ago
Well, rolling files feature creates (or overwrites) new file when limit is reached by design; I don't think that it is good idea to COPY contents of current file to new chunk just to preserve 'main' file as latest log file. File rename will not work for your purpose as 'tail -f' cannot switch to new file handler in runtime.
I'm planning to have rolling over 10 files with FileLimitSize of 2 MB. So MyLog9.log should contain the oldest content.
This means that when limit is reached you'll need up to 9 file renames, and what if one of these files is used (or locked)?
BTW, why you cannot just just choose most-recent log file by last write time for "tail -f" - say, with "ls -Art | tail -n 1"? I don't understand why file names are so important for you.
I agree with @dernippel. It is common that the 0
file contains the most recent content. In *nix it is usual that the current file has no number at all and that the older files are named LogFile.<number>.<optional extension>
.
I don't think that it is good idea to COPY contents of current file to new chunk just to preserve 'main' file as latest log file.
You could use File.Replace
for that.
@Sebazzz for my purposes file names are not important, but if you want to add this behavior for rolling files your PR is welcome. Only requirement is to leave existing logic, and add an option to activate unix-like naming convention (I'm fan of backward compatibility when possible).
For testing purposes I've set this:
"FileSizeLimitBytes": 2000, "MaxRollingFiles": 10
and I want to follow the file (with tail -f or a tool like baretail). For this I need the last log entries in the "main" file but currently the new content is added in MyLog[number].log.
Is it possible to have the newest entries in the main file? I'm planning to have rolling over 10 files with FileLimitSize of 2 MB. So MyLog9.log should contain the oldest content.