Skip to content

Logging incorrectly uses CurrentCulture when formatting IEnumerable values #116979

@ArturDorochowicz

Description

@ArturDorochowicz

Description

Logging incorrectly uses CurrentCulture when formatting IEnumerable values.

Reproduction Steps

dotnet new console
dotnet add package Microsoft.Extensions.Logging
dotnet add package Microsoft.Extensions.Logging.Console

Change Program.cs to:

using System.Globalization;
using Microsoft.Extensions.Logging;

CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("pl-PL");

using var lf = LoggerFactory.Create(b => b.AddConsole());
var l = lf.CreateLogger<Program>();

var values = new object[] { new DateTime(), 3.14 };

l.LogInformation("ok: {P1} {P2}", values);
l.LogInformation("wrong: {Values}", [values]);

Run with dotnet run which prints:

info: Program[0]
      ok: 01/01/0001 00:00:00 3.14
info: Program[0]
      wrong: 1.01.0001 00:00:00, 3,14

Expected behavior

Both log lines should have the same formatting.

Actual behavior

Values in the second log entry are formatted with CurrentCulture (here pl-PL).

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

Using Microsoft.Extensions.Logging 9.0.6

Metadata

Metadata

Assignees

Labels

area-Extensions-Loggingbugin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions