提交 94efa89a 编写于 作者: S Sam Harwell

Avoid trying to write log files longer than max path

Fixes #12106
上级 d0781848
......@@ -68,6 +68,15 @@ private static void FirstChanceExceptionHandler(object sender, FirstChanceExcept
var testName = CaptureTestNameAttribute.CurrentName ?? "Unknown";
var logDir = Path.Combine(assemblyDirectory, "xUnitResults", "Screenshots");
var baseFileName = $"{DateTime.Now:HH.mm.ss}-{testName}-{eventArgs.Exception.GetType().Name}";
var maxLength = logDir.Length + 1 + baseFileName.Length + ".Watson.log".Length;
const int MaxPath = 260;
if (maxLength > MaxPath)
{
testName = testName.Substring(0, testName.Length - (maxLength - MaxPath));
baseFileName = $"{DateTime.Now:HH.mm.ss}-{testName}-{eventArgs.Exception.GetType().Name}";
}
ScreenshotService.TakeScreenshot(Path.Combine(logDir, $"{baseFileName}.png"));
var exception = eventArgs.Exception;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册