Skip to content
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

Added support for customising date in filename #343

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

Conversation

RandomTIP
Copy link

Address (Partially): #243

Changes:

  • PathRoller now recognizes and uses {Date} placeholder in file name.
  • Regex matching and directory search patterns have been adjusted for use with {Date} placeholder

This update should Enable users to use following configuration:

var config = new LoggerConfiguration()
            .WriteTo.File("{Date}-log.txt", rollingInterval: RollingInterval.Day);
var log = config.CreateLogger();

Unit Tests Added and Updated in:

  • TemplatePathRollerTests
  • RollingFileSinkTests

…aceholder.

 This commit simply adds support to include date at the start (instead of the end) of filename whenever needed.
 Relevant Tests were also added For PathRoller.cs in TemplatedPathRollerTests.cs

 This commit partially addresses serilog#243
@RandomTIP
Copy link
Author

I know this PR came out of nowhere, but I needed support for this for my project and thought I would send a PR to the original repo as well since the changes are quite simple and straightforward.

This partially addresses #243 without any sort of high level customization, I wanted to make it as simple as possible because, after one or two days worth of searching, I think most of the requests were only related to Date customization in filename.

I would appreciate and take into considaration any and all notes on this one

@RandomTIP RandomTIP changed the title Added support for customising date in filename by including Added support for customising date in filename Mar 10, 2025
@nblumhardt
Copy link
Member

Thanks @RandomTIP. This functionality is something we specifically decided to leave behind in Serilog.Sinks.RollingFile - using that package is the way to go, if you need {Date}, but otherwise, using your own fork of this sink is going to be the way forwards. Thanks again!

@RandomTIP
Copy link
Author

Thanks for the information. I was not able to gather that much myself for some reason... I assumed Serilog.Sinks.RollingFile was deprecated and that is why I overlooked it.

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