Current way hurts my European eyes, and prevents safe reuse of logged SQL for debugging etc.
Current: 01/02/2019 14:11:12 (DateTime.ToString() with InvariantCulture)
Proposed: Datetime.ToString("s")/DateTimeOffsset.ToString("o")
@ErikEJ it would be nice to discuss over examples to agree on how we want it to look.
See
https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings https://docs.microsoft.com/en-us/sql/t-sql/data-types/datetimeoffset-transact-sql
https://docs.microsoft.com/en-us/sql/t-sql/data-types/datetime-transact-sql
For System.DateTime:
2019-01-02T14:11:12
For System.DateTimeOffset:
2019-01-02T14:11:12.0000000-07:00
@Eilon Do you know of any guidance on formatting dates/times in logs? More generally, should log strings be formatted with the current culture or an invariant culture?
I would think invariant culture is best, for the same reason we don't localize log messages either. The current app's culture (especially in a web app) should really not affect the log messages that are written.
Interesting. In EF6, we localize all log messages; I wasn't aware it was a thing to not do so. (In EF Core we have log messages set up for localization, although we haven't done it yet. If we're never going to localize them, then we should probably re-structure some things.)
Yeah logs are intended to be invariant, and certainly not dependent on the app's current culture. The app's current culture is usually set to what the user's culture is, which is almost never the same person as whoever looks at the logs of the app.
I think in most parts that I've seen, the strings used for log messages are string literals, not resources.
Triage decision: we will use Erik's suggested format. Putting it back on the backlog, but we would accept a PR for it. 馃樃
@Eilon Thanks for the info. We'll make sure these strings never get localized.
Thanks @ErikEJ!
Most helpful comment
Triage decision: we will use Erik's suggested format. Putting it back on the backlog, but we would accept a PR for it. 馃樃
@Eilon Thanks for the info. We'll make sure these strings never get localized.