-
-
Notifications
You must be signed in to change notification settings - Fork 334
Compressing rolled files #234
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
Comments
@FreeAndNil thanks for replying! Short answer = No I was already aware of this feature (it is my ALT-1 above) but unfortunately it does not cover the rolling-on-date use case. Only works on rolling-on-size. As I saw during my testing. So, I'd like to override a method that log4net calls exactly one time when log4net decides to roll (on size or on date). My impression is that this method is |
@FreeAndNil thanks for the quick modification of the code! I've seen the code change, it is what I think it could solve my problem. To be sure it fixes my problem, I need to test it in my environment and see the zips being created. I'm using now a nuget package reference in my project, would it be possible to create a beta log4net nuget package for testing? |
@FreeAndNil Excellent! Thank you. Let me test it tomorrow. I'll get back with the test results. |
Unfortunately ALT-3, overriding I see the new rolled files being created in File Explorer, but for some reason the I see the overriding of RollOverRenameFiles() method being called (only upon rollover on size, not on date). @FreeAndNil Any thoughts? How to create a zip of the |
@lraulea can you set a breakpoint in RollOverTime()? |
@FreeAndNil Sure, let me check it tomorrow. |
Below the configuration data Still TODO: set a breakpoint in RollOverTime()
|
@lraulea in AdjustFileBeforeAppend() "File" only changes when log4net already has a file open and decides to close it and create a new one. |
@FreeAndNil Current process is running before and after the top-of-the-hour, but AdjustFileBeforeAppend misses the rollover on time => correction: it does not miss, sorry, just retested. About the TODO: breakpoint added in RollOverTime() base, no hit after crossing the top-of-the-hour. Any thoughts on why the RollOverTime() is never called upon rolling on date? |
Does the process log something before |
Yes, it logs. I would expect that RollFile() is always called when rolling. But it seems not the case. Thanks for your help. I'll continue debugging next week. |
@FreeAndNil Just to conclude the day with good news.
Use-case 1: process is running The above override of AdjustFileBeforeAppend() works actually just fine during my latest tests. Sorry for the confusion. I thought I've seen few times that the zip was not done, but I cannot reproduce the issue, I have to look further here. Use-case 2: process (app) is restarted after the top-of-the-hour A log file has been created, the app has been closed, after the rollover date moment the app is restarted. The AdjustFileBeforeAppend() has currentFile equal to File (!). Consequence of this is that the file created in previous instance, is left unzipped. @FreeAndNil any thoughts how I can use log4net to zip files between instances of the same process? |
@lraulea You can override OpenFile() and check (before base.OpenFile()) whether the file already exists. |
@FreeAndNil override OpenFile(), interesting, I'll investigate it, thank you. |
@FreeAndNil as far as I'm concerned, you can reject #237 |
@FreeAndNil I've done some testing. My existing files are all The As a result the I have ? |
Before |
Good idea. |
@FreeAndNil thanks for your help! |
@FreeAndNil may i share with you a test result? overriding the
Results:
The following line is unexpected:
because LM-Starter-202504011533.log.0 has just been created just two lines above. It seems there are two OpenFile() calls on opening LM-Starter-202504011533.log.0 The second OpenFile() call zips it (tips it in this test) but the second OpenFile() still creates LM-Starter-202504011533.log.0 @FreeAndNil do you recognize this double OpenFile()? It looks intermitent, not always. |
Sure!
I've tested with 3.0.5-preview.1, probably #232 is not part of this |
@lraulea I've published https://github.com/apache/logging-log4net/releases/tag/rc%2F3.0.5-preview.2 with the relevant changes. |
@FreeAndNil unfortunately not much better I've noticed that these 191 bytes are actually empty files. Quite many empty files are created, sometimes I get the impression that the empty files are re-created because the creation data changes.
Let's get a step back and see what the use case was:
@FreeAndNil could this new zip-old-rolled-file feature be cleanly built inside log4net? Hooking into log4net with overrides seems too complex. |
@lraulea it is possible to implement this feature inside log4net. You can consider sponsoring me. |
Great! |
@FreeAndNil I'll have to come back on this next week |
@FreeAndNil still on going, next week I know more. |
@lraulea I’m planning to dive deeper into the topic this week and next. Once I’ve had a proper look, I’ll be in a better position to estimate how long it might take. |
@FreeAndNil thanks 🙏 |
I'm really struggling to find a way to zip the rolled old
fromFile
, at the moment that log4net decides to rollover on date. I don't see any direct way to get notified if a log file was rolled, only indirectly and incomplete.My kind request is to implement ALT-3, if possible.
ALT-1: override RollOverRenameFiles() method
Result= NOK
-only works for rollover based on size
-for rollover based on date, this method is not called, no zip
ALT-2: override AdjustFileBeforeAppend() method
Result= NOK
-works for rollover based on size on same day
-when crossing a date boundary,
currentFile
differs fromFile
=> zip OK-when starting the main app the next day, it misses the previous day file => no zip
ALT-3: override RollFile(string fromFile, string toFile) method
Cannot override now because method is not
virtual
So, my request is: could this
RollFile()
be made virtual?Thanks!
Greetings,
Liviu
The text was updated successfully, but these errors were encountered: