ARTICLE AD BOX
I am having an issue formatting the date in the filename using the appsettings.json file for a C# worker service.
My current config looks like this:
Serilog": { "WriteTo": [ { "Name": "File", "Args": { "path": "C:\\Program Files (x86)\\Alarm\\AlarmServiceLogs\\AlarmService.txt", "rollingInterval": "Day" } } ] }It's very basic. I tried adding {Date: yyyy-DD-MM} and other variations as well as using pathFormat rather than path, but that all just seems to add the verbatum text to the log file name.
Is this doable from the .json file? Otherwise I will do it directly in code as I have with other logs. Just trying to be consistent with my log file naming.
760k186 gold badges1.4k silver badges1.5k bronze badges
1
First you have to make sure you configured you application to load the config correctly:
Example from Serilog:
If you did this you have to correctly structure your json like this: https://github.com/serilog/serilog-sinks-rollingfile?tab=readme-ov-file#controlling-event-formatting
{ "Serilog": { "WriteTo": [ { "Name": "RollingFile", "Args": { "pathFormat": "log-{Date}.txt" } } ] } }1032 silver badges11 bronze badges
2 Comments
Your example here is using the rolling file sink, which has been deprecated for a long time. Instead, the file sink should be used, which supports rolling functionality.
2025-11-26T14:07:26.6Z+00:00
Explore related questions
See similar questions with these tags.

