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

Rolling file UTC support

Open dmch-dev opened this issue 7 years ago • 8 comments

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?

dmch-dev avatar May 21 '18 23:05 dmch-dev

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!

nblumhardt avatar Sep 21 '18 23:09 nblumhardt

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.

progmech avatar May 15 '20 07:05 progmech

Hi,

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

LukasZalkauskas avatar Oct 26 '20 09:10 LukasZalkauskas

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 avatar Oct 26 '20 22:10 nblumhardt

Hi,

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

ActualPlayer avatar Jun 07 '21 11:06 ActualPlayer

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));

6bee avatar Oct 04 '23 15:10 6bee

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

https://github.com/serilog/serilog/issues/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.

nblumhardt avatar Oct 05 '23 10:10 nblumhardt