private static string CreateLogFileName()

in src/Microsoft.VisualStudio.Extensibility.Testing.Xunit.Shared/Harness/DataCollectionService.cs [160:185]


        private static string CreateLogFileName(string logDirectory, DateTimeOffset timestamp, string testName, string errorId, string logId, string extension)
        {
            const int MaxPath = 260;

            var path = CombineElements(logDirectory, timestamp, testName, errorId, logId, extension);
            if (path.Length > MaxPath)
            {
                testName = testName.Substring(0, Math.Max(0, testName.Length - (path.Length - MaxPath)));
                path = CombineElements(logDirectory, timestamp, testName, errorId, logId, extension);
            }

            return path;

            static string CombineElements(string logDirectory, DateTimeOffset timestamp, string testName, string errorId, string logId, string extension)
            {
                if (!string.IsNullOrEmpty(logId))
                {
                    logId = $".{logId}";
                }

                var sanitizedTestName = new string(testName.Select(c => char.IsLetterOrDigit(c) ? c : '_').ToArray());
                var sanitizedErrorId = new string(errorId.Select(c => char.IsLetterOrDigit(c) ? c : '_').ToArray());

                return Path.Combine(Path.GetFullPath(logDirectory), $"{timestamp:HH.mm.ss}-{testName}-{errorId}{logId}.{extension}");
            }
        }