When I try to output a numeric value with the currency format specifier using ILogger.LogInformation()
I get an unexpected symbol different from when I use Console.Log(string.Format())
. The later displays the expected dollar sign as the symbol where as the former displays something unprintable.
Sample Code
var services = new ServiceCollection();
services.AddLogging(x =>
{
x.AddDebug();
x.AddConsole();
});
var svcProvider = services.BuildServiceProvider();
var logger = svcProvider.GetRequiredService<ILoggerFactory().CreateLogger<Program>();
logger.LogInformation("Amount {0:C}", 100.0);
System.Diagnostics.Debug.WriteLine(string.Format("Amount {0:C}", 100.0));
Output from Debug
xyz.Program:Information: Amount ¤100.00
Amount $100.00
I see know way of configuring CultureInfo for the ILogger and I don't want to specify it each time I write. Also, I don't think this is relevant, but the code is being executed inside an async
method.
So is this a bug, are my expectations unrealistic, or am I doing something wrong?