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

Customize filename while using rolling policies #243

Open
Deilan opened this issue Sep 25, 2021 · 11 comments
Open

Customize filename while using rolling policies #243

Deilan opened this issue Sep 25, 2021 · 11 comments

Comments

@Deilan
Copy link

Deilan commented Sep 25, 2021

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

@osnipezzini
Copy link

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

@zivfuture
Copy link

any update?

@osnipezzini
Copy link

Any News?

@bartelink
Copy link
Member

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.

@DragonCoding-Reiko
Copy link

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.

@cocowalla
Copy link
Contributor

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

@DragonCoding-Reiko
Copy link

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.

@wzuqui
Copy link

wzuqui commented Jan 25, 2023

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

@nblumhardt
Copy link
Member

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.

@TooManyLeaves
Copy link

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.

@bartelink
Copy link
Member

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 #40 for the discussion that spawned it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants