-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
area-Extensions-Loggingbugin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Milestone
Description
Description
Logging should use InvariantCulture, but when LoggerMessage-generated method receives 7 or more arguments, the generated code incorrectly uses CurrentCulture for formatting.
Reproduction Steps
dotnet new console
dotnet add package Microsoft.Extensions.Logging
dotnet add package Microsoft.Extensions.Logging.Console
Change Program.cs to be:
using System.Globalization;
using Microsoft.Extensions.Logging;
partial class Program
{
static void Main()
{
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("fr-FR");
using var lf = LoggerFactory.Create(b => b.AddConsole());
var l = lf.CreateLogger<Program>();
LogSix(l, new DateTime());
LogSeven(l, new DateTime());
}
[LoggerMessage(LogLevel.Information, "six: {Value:dddd} {P1} {P2} {P3} {P4} {P5}")]
static partial void LogSix(ILogger logger, DateTime value, int p1 = 1, int p2 = 2, int p3 = 3, int p4 = 4, int p5 = 5);
[LoggerMessage(LogLevel.Information, "seven: {Value:dddd} {P1} {P2} {P3} {P4} {P5} {P6}")]
static partial void LogSeven(ILogger logger, DateTime value, int p1 = 1, int p2 = 2, int p3 = 3, int p4 = 4, int p5 = 5, int p6 = 6);
}Running with dotnet run prints this:
info: Program[937803807]
six: Monday 1 2 3 4 5
info: Program[1491867730]
seven: lundi 1 2 3 4 5 6
Expected behavior
Logging must always use InvariantCulture.
Actual behavior
Logging with six arguments uses InvariantCulture (prints "Monday").
But logging with seven arguments uses CurrentCulture and here prints "lundi".
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
Using Microsoft.Extensions.Logging 9.0.6
No response
Metadata
Metadata
Assignees
Labels
area-Extensions-Loggingbugin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged