-
Notifications
You must be signed in to change notification settings - Fork 61
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
Logger doesn't rotate files anymore #76
Comments
Could you clarify how exactly to reproduce the issue? It sounds like the same file is all the day until the max file size is reached, which is a correct behaviour. |
That could be the issue in the end. Originally I tried to rotate the files each day with a datestamp as it's identifier (instead of the numbering) but it doesn't seem to be supported so maybe that's why I was thinking it's a bug, whoops. |
I guess you wanted to have a constant number of log files based on date (like "last 20 days"), however current implementation doesn't store anywhere all 'previous' log file names (returned by |
Actually not. I wanted to use the same system as it's implemented now but instead of creating log files with names like "Log", "Log.1", "Log.2" and so on it would've been "Log-2024-11-18", "Log-2024-11-17", "Log-2024-11-16". |
Rotation means that log files are re-used, for instance log.txt -> log1.txt -> log2.txt -> log.txt -> log1.txt (old content is lost) -> log2.txt -> etc It is unclear for me how rotation can work on a date basis instead of indexes. It is definitely weird if a file with old date like 'Log-2024-11-17' is reused for logs dated 2024-11-14 (for instance). I guess what you are looking for is automatic cleanup when logs filename is based on date, and old dates are automatically removed (say only last N files are kept). I don't think that this cleanup should be a part of NReco.Logging.File because logs cleanup strategy can be very different (say, it can involve archiving old logs before removal) and this is actually an application-specific thing. This can be a background task in your .NET app, or you can call this handler in a separate thread from your custom "FormatLogFileName" handler - say, keep previously returned filename and when it changes, run a cleanup routine. Let me know if you need an example, I'll try to prepare it when I'll have a bit of free time. |
Oh the cleanup part I already got that's no issue. The part where I create logs based on a date-basis is the thing which I miss (or currently not have / can't achieve with the lib). If that's possible to do with the lib then it'd be great to know. Otherwise I may have to search for something else or fall back to an own implementation (which I actually don't want to do..) 🙂 |
Now I lost the understanding of desired behavior. You can already create logs on a date basis via FormatLogFileName handler, isn't it? You can either use or do not use the rolling files feature (which will work only for a concrete date). And if you need to clean up old logs (= keep only last N days) you can easily do that in your app's code (this can even be a call from FormatLogFileName when 'base' file name is changed). |
@VitaliyMF I think it would be good if it supports an option naming log files by date without specifying FormatLogFileName. I think it will be very useful. |
|
I see. But I think you can consider this scenario. We might want to change logging configuration through appsettings.json only without changing any code. |
@chenglidev technically configuration of date-based log file name through appsettings.json can be supported in this way: in
It is not obvious that {0} is actually refers to the DateTime.Now. Maybe it makes sense to use "{now}" instead and then replace "{now}" with "{0}"?.. |
@VitaliyMF OK. Thanks. Let me try that. |
Versions used
.NET: 8 and 9 (both don't work)
Microsoft.Extensions.Logging: 8.0.1 and 9.0.0 (both don't work)
NReco.Logging.File: 1.2.1
Description
Currently I got the issue that the rotation feature of logging isn't working anymore. I have no clue why but at the end of the day it always uses the same file (approx. until the max file size is reached).
I attach the code below, maybe you can find an issue?
Code sample
Additional comments
All in all it's a great lib! I am happy that there is a lightweight extension which handles file logging. 🙂
The text was updated successfully, but these errors were encountered: