Skip to content

Add ability for static base file and customizable file roll patterns. #345

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

jublin
Copy link

@jublin jublin commented Mar 17, 2025

In my work, a number of our projects use Serilog. One project has a task to revamp the logging to use items like Elastic/FluentD, but must also still output to a static file for developer/support engineer use in the field.

Given that a number of projects were using Serilog, this seemed an easier feature to add than to figure out other logging libraries/roll our own. Other sinks forked off of this removed the NETStandard 2.0 compatibility, which was a no-go for use on our end.

Did this in my own time both to help my work, but to have something I can use outside of work on my tinkering projects.

Adds 3 optional parameters:

  • keepPathStaticOnRoll (bool) - Keep the base file name passed in (log.txt for instance) as the base file.
  • customFormatFunc (Func<DateTime?,string>) - Function to give a custom format for rolling files. The yyyyMMDD format did not work for requirements.
  • customRollPattern (string) - A string regex pattern that will match the output of customFormatFunc. This must be provided when custom format is used, as the rollovers will not work (nor will it validate).

@nblumhardt
Copy link
Member

Thanks for jumping in! This feature has been discussed here in the past and, while it's a useful feature, it comes with some complexity and implementation challenges we're not keen to take on in this sink.

A fork supporting this feature has been developed in https://github.com/dfacto-lab/serilog-sinks-file, and I think contributions/improvements over there would be welcomed (best to ping the maintainer and check what's currently on the list :-))

@jublin
Copy link
Author

jublin commented Mar 19, 2025

A fork supporting this feature has been developed in https://github.com/dfacto-lab/serilog-sinks-file, and I think contributions/improvements over there would be welcomed (best to ping the maintainer and check what's currently on the list :-))

The main problem in that is .net8.0 only. I see a netsandard2.0 pull request that updates it, but it has sat there for 5 months. Considering this repository has more active development, and does netstandard already, that's why I chose to do a pr here.

https://github.com/yoav-melamed/serilog-sinks-asyncfile also does this, and I have a PR there to implement netstandard.

@nblumhardt
Copy link
Member

nblumhardt commented Mar 20, 2025

Thanks for the follow up 👍

Keeping things healthy/maintained over a long time span is definitely an unsolved problem, unfortunately. Being really strategic about feature additions is how this project is still going.

Forking the fork (or this project) might be the easiest option at this point. A maintained wrapper around this project that reuses its FileSink but adds new rolling policies would be really appreciated out there and might be easier to update long-term, in case that's an option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants