serilog-sinks-file-archive icon indicating copy to clipboard operation
serilog-sinks-file-archive copied to clipboard

Add Retention Limit configuration

Open frelis opened this issue 4 years ago • 6 comments

Add a Retention Limit in number of files of maximum total size occupied by the log files (I will be more interested in the first option)

Thanks for the good work. PS: I'm programing in VB.net

frelis avatar Jun 08 '20 20:06 frelis

Thanks for opening this! This sink would indeed fit a much wider variety of use cases if it supported file retention, instead of simply overwriting the target file on every roll.

This functionality shouldn't be too difficult to add either, since it already exists in the file sink.

I'll try to add it this week, but it depends on how busy things are 👍

cocowalla avatar Jun 08 '20 20:06 cocowalla

Hmm, so, after looking into this, it's actually more complex that I thought, for 2 reasons:

  1. The hook doesn't have access to the Serilog File Sink configuration (I can work around this though, or can append a date-based suffix to archived files)
  2. Because this hook supports tokens in target paths names, the archived files could be spread across several folders, and there is no guarantee that this hook actually created all folders matching the relevant patterns

So, I could add retention, but would only enable it if no tokens were used in the target path - but my guess is that most would prefer to use token replacement (to organise archived files into folders by date) and manage retention themselves, so I think I'd be adding extra complexity that few would use.

Very much open to other ideas here 😅

cocowalla avatar Jul 01 '20 15:07 cocowalla

My suggestion is to add some wildcard parameter which can be used to detect the files. Something like ../_logs/archive/*/*/loggedService/log*.txt.gz (or Regex) which will match files like ../_logs/archive/2021/02/loggedService/log20210225.txt.gz. It should be enough for most of use cases.

I would love such feature. If it's not implemented here, I'll have to fork the project in few days :)

mirousek avatar Feb 26 '21 09:02 mirousek

My suggestion is to add some wildcard parameter which can be used to detect the files. Something like ../_logs/archive/*/*/loggedService/log*.txt.gz (or Regex) which will match files like ../_logs/archive/2021/02/loggedService/log20210225.txt.gz. It should be enough for most of use cases.

I would love such feature. If it's not implemented here, I'll have to fork the project in few days :)

Did you end up forking the repo and adding this functionality?

yaronyudov avatar May 19 '21 13:05 yaronyudov

My suggestion is to add some wildcard parameter which can be used to detect the files. Something like ../_logs/archive/*/*/loggedService/log*.txt.gz (or Regex) which will match files like ../_logs/archive/2021/02/loggedService/log20210225.txt.gz. It should be enough for most of use cases. I would love such feature. If it's not implemented here, I'll have to fork the project in few days :)

Did you end up forking the repo and adding this functionality?

Not yet. The archives are small enough to have priorities elsewhere. But it's in my backlog and current plan is to do it in few weeks (along with .xz compression).

mirousek avatar May 19 '21 21:05 mirousek

+1 It would be very nice, if we could get this feature. We have now implement ourer own hosekeeper method.

christopherpross avatar Mar 07 '24 16:03 christopherpross