serilog-sinks-file icon indicating copy to clipboard operation
serilog-sinks-file copied to clipboard

Customize filename while using rolling policies

Open Deilan opened this issue 3 years ago • 11 comments

Requesting a out-of-the-box capability to customize a filename while using rolling policies.

Deilan avatar Sep 25 '21 19:09 Deilan

I agree, some custom config to provide a name without date timestamp like 'log.txt' not 'log-220630.txt'

osnipezzini avatar Jun 30 '22 16:06 osnipezzini

any update?

zivfuture avatar Sep 07 '22 06:09 zivfuture

Any News?

osnipezzini avatar Sep 07 '22 13:09 osnipezzini

An 'update' and/or 'news' would require a) an agreed spec b) a PR implementing that

  • The first bit can be helped by people providing details of their requirements and/or a proposed API - this is a reasonable place for such a discussion to take place (given this sink has very broad usage, so it's worth getting the design right such that it covers the needs of as many people as possible; removing misfeatures and/or changing behavior afterward is not going to be viable).
  • The second bit is a matter of someone somewhere making the time to implement it.

bartelink avatar Sep 07 '22 16:09 bartelink

So it's not possible to let the rolling policy save the file in another folder than the original one? Because I really would need that to keep it organized.

DragonCoding-Reiko avatar Oct 05 '22 20:10 DragonCoding-Reiko

@ReikoTigon maybe this plugin would work for you: cocowalla/serilog-sinks-file-archive ?

cocowalla avatar Oct 05 '22 20:10 cocowalla

Hmm if i get the plugin correctly it moves them instead of deleting them? What I want is use the defualt mechanism by srilog to apply the daily rolling pollicy with 7 days, but tho move those old 7 logs to a dedicated "logs" folder, whereas the current log is located in the main folder.

or be able to name the current log sth like "current.log" and all the old logs "log_DATE.log" like it would do atm.

DragonCoding-Reiko avatar Oct 05 '22 20:10 DragonCoding-Reiko

In NLog, there are some properties such as "archiveEvery" and "archiveDateFormat" that only modify archived files. Is it possible to customize the same for serilog-sinks-file?

see: https://nlog-project.org/documentation/v3.2.1/html/Properties_T_NLog_Targets_FileTarget.htm

wzuqui avatar Jan 25 '23 16:01 wzuqui

Hi folks!

Most of this sink's heavy lifting (formatting and so on) is implemented by Serilog (MessageTemplateTextFormatter), or by plugged in formatters like those from Serilog.Expressions (ExpressionTemplate) or Serilog.Formatting.Compact (CompactJsonFormatter).

It's fairly straightforward to wire these things up in a new sink that behaves in one of the ways suggested so far in this thread. Sinks are just simple classes that implement ILogEventSink, which is itself a simple interface with a method Emit(LogEvent).

The hesitation to add more filename rolling styles and path formatting here is because although it's not a lot of code to construct a sink for one of these cases targeting one platform, the complexity of trying to support everything in the one sink is likely to turn it into a much heavier package than what we have today, and there's not a lot of enthusiasm for that among the Serilog maintainers as far as I can tell.

If anyone's keen to implement their own specific case as a separate sink class, using formatters and so on from the packages mentioned above, and runs into trouble I'd be very happy to help - dropping a question on Stack Overflow tagged serilog will get my eyes and many others on it.

Unfortunately although it's nice to have a place to comment, this ticket is likely to be unproductive and noisy so I'll limit further activity to updates from maintainers. If anyone out there makes progress on either an implementation of a standalone sink with different rolling or formatting behavior, or a fork that adds more sophisticated configuration, we can post some links to their work here.

nblumhardt avatar Jan 25 '23 22:01 nblumhardt

If customizing filenames is a requirement, and you have the option of choosing your logging framework, you might consider taking a look at NLog, instead.

TooManyLeaves avatar Nov 06 '23 03:11 TooManyLeaves

There is also a fork of this Sink, Serilog.Sinks.PersistentFile that was started with the explicit aim of implementing some of these facilities; see https://github.com/serilog/serilog-sinks-file/issues/40 for the discussion that spawned it

bartelink avatar Nov 06 '23 07:11 bartelink