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

Rolling file UTC support #56

Open
dmch-dev opened this issue May 21, 2018 · 7 comments
Open

Rolling file UTC support #56

dmch-dev opened this issue May 21, 2018 · 7 comments

Comments

@dmch-dev
Copy link

dmch-dev commented May 21, 2018

Hi.
I want to configure serilog-sinks-file to create new log file each day according to UTC.

Please, take a look at your class Clock.cs:
https://github.com/serilog/serilog-sinks-file/blob/dev/src/Serilog.Sinks.File/Sinks/File/Clock.cs
Here you're using DateTime.Now, but what about using DateTime.UtcNow?

Is there any way to configure it to use UTC? Otherwise can you please add this feature?

@nblumhardt
Copy link
Member

Thanks for the suggestion, and sorry about the slow reply. Doing this seems entirely reasonable, but it's on the borderline of being too much of an edge case for us to want to add a setting for it. Forking the sink (it's a very small codebase) could be a decent option at this point - I'll close this issue as I don't think we'll make the change in the near future, but if enough people need the same thing and stumble across this ticket, we can definitely reevaluate. Cheers!

@progmech
Copy link

Hello,
It sounds strange that the sink doesn't support such a feature. I write my logs in UTC and now, the date in a log file name is very often younger than date of records in the file. Of couse I can use the Reflection, but I guess it is better if this functionality will be implemented out of the box.
Thanks.

@LukasZalkauskas
Copy link

Hi,

I would also be interested to have such feature out of the box.

@nblumhardt
Copy link
Member

Let's give this some more thought 👍

I don't think we'd open up the static hook point as-is (it's only there to facilitate testing); it'd be nicer to get rid of it and integrate through a public clock parameter ... somewhere.

The case against this is the proliferation of arguments to File(), which is a somewhat poor case, but has kept us from being weighed down by too much combinatorial complexity so far :-)

@nblumhardt nblumhardt reopened this Oct 26, 2020
@ActualPlayer
Copy link

Hi,

How about next to the RollingInterval.Day, we could also use a RollingInterval.UtcDay?

@6bee
Copy link

6bee commented Oct 4, 2023

It actually doesn't appear to be such a rare scenario and I'm wondering why this issue is still not solved after five years?!

Anyway, meanwhile we use this HACK as a workaround:

var fileSinkTypes = typeof(Serilog.Sinks.File.FileSink).Assembly.GetTypes();
var clockType = fileSinkTypes.FirstOrDefault(x => string.Equals(x.FullName, "Serilog.Sinks.File.Clock", StringComparison.Ordinal));
var timestampProviderField = clockType?.GetField("_dateTimeNow", BindingFlags.Static | BindingFlags.NonPublic);
timestampProviderField?.SetValue(null, new Func<DateTime>(() => DateTime.UtcNow));

@nblumhardt
Copy link
Member

@6bee many other more interesting things got done instead - time and attention is finite unfortunately :-)

serilog/serilog#1920 might evolve into a general solution to this, time providers can select their local time zone, which in this case could be set to UTC.

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

7 participants