serilog / serilog-sinks-file

Write Serilog events to files in text and JSON formats, optionally rolling on time or size
Apache License 2.0
334 stars 117 forks source link

I want my Log file name in the format "D:\Log\FileName-{Date}-INew.txt" #298

Closed amande4x closed 1 year ago

amande4x commented 1 year ago

I want my generated text file name of format. "D:\Log\FileName-{Date}-INew.txt" Currently its appending Date towards the end of the file, "D:\Log\FileName-INew-20231010.txt" Expected "D:\Log\FileName-20231010-INew.txt"

            .WriteTo.Logger(l =>
            {
                l.WriteTo.File(
                        config.GetValue<string>(GenericConstants.TentFilePathKey)!,
                        rollingInterval: RollingInterval.Day,
                        retainedFileCountLimit: null,
                        outputTemplate: GenericConstants.LogOutputTemplateToken
                );
                l.Filter.ByIncludingOnly(e => e.Properties.ContainsKey(GenericConstants.NewFile));
            });
bartelink commented 1 year ago

Duplicate of #243 - the logic for generating filenames is definitely minimal in nature at present, but lots of people put up with that spartan nature.

Solving that would involve:

In particular, I'd read this reply from Nick, which outlines the thinking as to why the naming strategy is not necessarily something that there's appetite to add a lot of complexity to.

There are some forks too, which may have and/or consider adding such a facility, e.g. https://github.com/dfacto-lab/serilog-sinks-file

bartelink commented 1 year ago

Had left this open in case you wanted to respond; assuming the above covers it