Skip to content

Commit c32fff3

Browse files
authored
Use internationally viable formatting for dates used in, for example, file paths (#46745)
Fixes #46727 Fixes #37932 (@MiYanni commented that it looks similar to the issue I'd been looking at. Turns out 46727 is a dupe, but since I have a PR out already, I'll leave them up and close both via this.) This replaces culture-sensitive ToString calls on DateTime.Now with string.Create(CultureInfo.InvariantCulture, $"[{DateTime.Now:yyyyMMdd}]") (or equivalent). This had been used in a file path and errored when using certain calendars.
1 parent b6da3a7 commit c32fff3

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/Cli/dotnet/Installer/Windows/TimestampedFileLogger.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Collections.Concurrent;
5+
using System.Globalization;
56
using System.IO.Pipes;
67
using System.Runtime.Versioning;
78

@@ -42,7 +43,7 @@ public string LogPath
4243
/// <summary>
4344
/// The locale-neutral timestamp prefix.
4445
/// </summary>
45-
protected static string TimeStamp => $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}]";
46+
protected static string TimeStamp => $"[{string.Create(CultureInfo.InvariantCulture, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}")}]";
4647

4748
/// <summary>
4849
/// Creates a new <see cref="TimestampedFileLogger"/> instance.

src/Cli/dotnet/commands/dotnet-workload/install/NetSdkMsiInstallerClient.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Globalization;
45
using System.Linq;
6+
using System.Runtime.CompilerServices;
57
using System.Runtime.Versioning;
68
using System.Text.Json;
79
using Microsoft.DotNet.Cli;
@@ -1125,7 +1127,7 @@ public static NetSdkMsiInstallerClient Create(
11251127
bool shouldLog = true)
11261128
{
11271129
ISynchronizingLogger logger =
1128-
shouldLog ? new TimestampedFileLogger(Path.Combine(Path.GetTempPath(), $"Microsoft.NET.Workload_{Environment.ProcessId}_{DateTime.Now:yyyyMMdd_HHmmss_fff}.log"))
1130+
shouldLog ? new TimestampedFileLogger(Path.Combine(Path.GetTempPath(), string.Create(CultureInfo.InvariantCulture, $"Microsoft.NET.Workload_{Environment.ProcessId}_{DateTime.Now:yyyyMMdd_HHmmss_fff}.log")))
11291131
: new NullInstallerLogger();
11301132
InstallClientElevationContext elevationContext = new(logger);
11311133

0 commit comments

Comments
 (0)