Skip to content

Commit 26c78ee

Browse files
authored
Create folders for debug log file (#6546)
1 parent 5887e41 commit 26c78ee

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/Servers/IIS/AspNetCoreModuleV2/CommonLib/debugutil.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void SetDebugFlags(const std::wstring &debugValue)
123123
}
124124
}
125125

126-
bool CreateDebugLogFile(const std::wstring &debugOutputFile)
126+
bool CreateDebugLogFile(const std::filesystem::path &debugOutputFile)
127127
{
128128
try
129129
{
@@ -140,6 +140,11 @@ bool CreateDebugLogFile(const std::wstring &debugOutputFile)
140140
CloseHandle(g_logFile);
141141
g_logFile = INVALID_HANDLE_VALUE;
142142
}
143+
144+
// ignore errors
145+
std::error_code ec;
146+
create_directories(debugOutputFile.parent_path(), ec);
147+
143148
g_logFile = CreateFileW(debugOutputFile.c_str(),
144149
(GENERIC_READ | GENERIC_WRITE),
145150
(FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE),
@@ -348,13 +353,13 @@ DebugPrintW(
348353
WORD eventType;
349354
switch (dwFlag)
350355
{
351-
case ASPNETCORE_DEBUG_FLAG_ERROR:
356+
case ASPNETCORE_DEBUG_FLAG_ERROR:
352357
eventType = EVENTLOG_ERROR_TYPE;
353358
break;
354-
case ASPNETCORE_DEBUG_FLAG_WARNING:
359+
case ASPNETCORE_DEBUG_FLAG_WARNING:
355360
eventType = EVENTLOG_WARNING_TYPE;
356361
break;
357-
default:
362+
default:
358363
eventType = EVENTLOG_INFORMATION_TYPE;
359364
break;
360365
}

src/Servers/IIS/IIS/test/Common.FunctionalTests/LogFileTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,18 @@ public async Task InvalidFilePathForLogs_ServerStillRuns(TestVariant variant)
8585

8686
[ConditionalTheory]
8787
[MemberData(nameof(TestVariants))]
88+
[RequiresNewShim]
8889
public async Task StartupMessagesAreLoggedIntoDebugLogFile(TestVariant variant)
8990
{
9091
var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant, publish: true);
9192
deploymentParameters.HandlerSettings["debugLevel"] = "file";
92-
deploymentParameters.HandlerSettings["debugFile"] = "debug.txt";
93+
deploymentParameters.HandlerSettings["debugFile"] = "subdirectory\\debug.txt";
9394

9495
var deploymentResult = await DeployAsync(deploymentParameters);
9596

9697
await deploymentResult.HttpClient.GetAsync("/");
9798

98-
AssertLogs(Path.Combine(deploymentResult.ContentRoot, "debug.txt"));
99+
AssertLogs(Path.Combine(deploymentResult.ContentRoot, "subdirectory", "debug.txt"));
99100
}
100101

101102
[ConditionalTheory]

0 commit comments

Comments
 (0)