question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to change the log file name when using day-based rolling files in 4.0.0?

See original GitHub issue

As 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:closed
  • Created 5 years ago
  • Reactions:19
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
feO2xcommented, May 22, 2018

@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.

2reactions
nblumhardtcommented, May 18, 2018

Hi @feO2x - thanks for the note.

The {Date} specifier used with RollingFile 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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found