From 26c78ee5424155783b3f8a7d6d3067e15f902815 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 10 Jan 2019 12:03:54 -0800 Subject: [PATCH] Create folders for debug log file (#6546) --- .../IIS/AspNetCoreModuleV2/CommonLib/debugutil.cpp | 13 +++++++++---- .../IIS/test/Common.FunctionalTests/LogFileTests.cs | 5 +++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/debugutil.cpp b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/debugutil.cpp index 3492be7354..ea8539c1b4 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/debugutil.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/debugutil.cpp @@ -123,7 +123,7 @@ void SetDebugFlags(const std::wstring &debugValue) } } -bool CreateDebugLogFile(const std::wstring &debugOutputFile) +bool CreateDebugLogFile(const std::filesystem::path &debugOutputFile) { try { @@ -140,6 +140,11 @@ bool CreateDebugLogFile(const std::wstring &debugOutputFile) CloseHandle(g_logFile); g_logFile = INVALID_HANDLE_VALUE; } + + // ignore errors + std::error_code ec; + create_directories(debugOutputFile.parent_path(), ec); + g_logFile = CreateFileW(debugOutputFile.c_str(), (GENERIC_READ | GENERIC_WRITE), (FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE), @@ -348,13 +353,13 @@ DebugPrintW( WORD eventType; switch (dwFlag) { - case ASPNETCORE_DEBUG_FLAG_ERROR: + case ASPNETCORE_DEBUG_FLAG_ERROR: eventType = EVENTLOG_ERROR_TYPE; break; - case ASPNETCORE_DEBUG_FLAG_WARNING: + case ASPNETCORE_DEBUG_FLAG_WARNING: eventType = EVENTLOG_WARNING_TYPE; break; - default: + default: eventType = EVENTLOG_INFORMATION_TYPE; break; } diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/LogFileTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/LogFileTests.cs index e93b4f007a..f5f7a3ba3a 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/LogFileTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/LogFileTests.cs @@ -85,17 +85,18 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalTheory] [MemberData(nameof(TestVariants))] + [RequiresNewShim] public async Task StartupMessagesAreLoggedIntoDebugLogFile(TestVariant variant) { var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant, publish: true); deploymentParameters.HandlerSettings["debugLevel"] = "file"; - deploymentParameters.HandlerSettings["debugFile"] = "debug.txt"; + deploymentParameters.HandlerSettings["debugFile"] = "subdirectory\\debug.txt"; var deploymentResult = await DeployAsync(deploymentParameters); await deploymentResult.HttpClient.GetAsync("/"); - AssertLogs(Path.Combine(deploymentResult.ContentRoot, "debug.txt")); + AssertLogs(Path.Combine(deploymentResult.ContentRoot, "subdirectory", "debug.txt")); } [ConditionalTheory]