Efcore: Improve logging of datetime parameter values

Created on 2 Aug 2017  路  8Comments  路  Source: dotnet/efcore

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

closed-fixed good first issue help wanted type-enhancement

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.

All 8 comments

@ErikEJ it would be nice to discuss over examples to agree on how we want it to look.

@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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bricelam picture bricelam  路  74Comments

anpete picture anpete  路  100Comments

vijayantkatyal picture vijayantkatyal  路  321Comments

matteocontrini picture matteocontrini  路  88Comments

divega picture divega  路  146Comments