Consider the following Console App code:
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
DateTime date = new DateTime(2014, 01, 19);
Console.WriteLine("{0}", date); // Prints 19/01/2014
Debug.WriteLine("{0}", date); // Prints 01/19/2014
Debug.WriteLine(date); // Prints 19/01/2014
As noted in the comments, the Console.WriteLine()
prints 19/01/2014
while the Debug.WriteLine()
prints 01/19/2014
.
Even worse - Debug.WriteLine("{0}", date)
gives different output from Debug.WriteLine(date)
...
Is it expected that Debug.WriteLine()
ignores the thread's culture settings?
Is there a way to make Debug.WriteLine()
use the thread's culture settings? Or must I use String.Format()
and pass the result to Debug.WriteLine()
?
(Note: I'm running this on Windows 8.1 64-bit, en-GB, using Visual Studio 2013 with .Net 4.51 with a debug AnyCPU build.)
This is explicitly handled in the source.
It makes sense, too.
Debug output should not be affected by the end-users culture; you want your debug logs to be consistent no matter where the code is running.