How to change the log file name when using day-based rolling files in 4.0.0?
See original GitHub issueAs you have announced recently, configuring rolling files is possible with the Serilog.Sinks.File
package since version 4.0.0. Is there any way to configure the output format for file names when using day-based rolling files?
Consider the following logger configuration:
new LoggerConfiguration().WriteTo.File(filePath, rollingInterval: RollingInterval.Day);
When I set filePath
to MyLog.log
then the resulting file name would be MyLog20180329.log
. How can I get to the following format: 2018-03-29 MyLog.log
? The {Date}
specifier that was present in Serilog.Sinks.RollingFile
seems to be not supported in this package.
I’m currently migrating one of our services from Log4Net to Serilog and we would like to keep the existing name template for our log files.
Thanks for your help in advance!
Issue Analytics
- State:
- Created 5 years ago
- Reactions:19
- Comments:8 (3 by maintainers)
Top Results From Across the Web
log4j - how to change filename in my rolling file appender ...
Try setting fileName to just logs/application.log and use the date format you want for archived files in filePattern .
Read more >A Guide to Rolling File Appenders
A quick and practical guide to using rolling file appenders in popular Java logging libraries.
Read more >Logging - Operations Manual
This appender is configured with the filePattern attribute, which specifies a file pattern to be used when the file is rolled. The pattern...
Read more >How can I name my log files according to the date?
I have tried to do something like date=date and then name my file $date.txt but the output was date.txt. Fun thing, I asked...
Read more >log device-disable | FortiAnalyzer 7.4.0
Log files rolling schedule (days of the week). When when is set to weekly , you can configure days , hour , and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@nblumhardt When I placed
{Date}
in the pathFormat using only Serilog.Sinks.File 4.0.0 package, this was not resolved (the resulting log files were named “{Date} file20180522.log”). Currently, we use Serilog.Sinks.Rollingfile and stick with the date format without dashes.Hi @feO2x - thanks for the note.
The
{Date}
specifier used withRollingFile
produces identical filenames to the ones used in this package (the internals are directly copied over from that codebase).At present no filename customization is supported - it’s a reasonable requirement, but hasn’t ended up critical enough for a design to make its way through the works. How does it stand for you - is changing the filename format a viable option, or are you blocked on this one? Thanks!