Cysharp / ZLogger

Zero Allocation Text/Structured Logger for .NET with StringInterpolation and Source Generator, built on top of a Microsoft.Extensions.Logging.
MIT License
1.25k stars 88 forks source link

How to format log entry timestamp? #31

Closed robertmircea closed 3 years ago

robertmircea commented 3 years ago

Is it possible to change the log's timestamp format for text logger? Currently I am using:

var prefixFormat = ZString.PrepareUtf8<string, DateTime>("{0} [{1}] ");
options.PrefixFormatter = (writer, info) => prefixFormat.FormatTo(ref writer, ConvertLoggingLevel(info.LogLevel), info.Timestamp.DateTime.ToLocalTime());

and obtain the following output:

DBUG [11/15/2020 01:22:30] Running ..........

but I would like a different date format like dd-MM-YYYY HH:mm:ss.fff

robertmircea commented 3 years ago

Bump

neuecc commented 3 years ago

https://github.com/Cysharp/ZLogger#format-and-datetime-handling