diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/WebConfigTransform.cs b/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/WebConfigTransform.cs index 563e2a00e..1db5cc8c8 100644 --- a/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/WebConfigTransform.cs +++ b/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/WebConfigTransform.cs @@ -60,7 +60,6 @@ private static void TransformAspNetCore(XElement aspNetCoreElement, string appNa // Forward slashes currently work neither in AspNetCoreModule nor in dotnet so they need to be // replaced with backwards slashes when the application is published on a non-Windows machine var appPath = Path.Combine(".", appName).Replace("/", "\\"); - var logPath = Path.Combine(configureForAzure ? @"\\?\%home%\LogFiles" : @".\logs", "stdout").Replace("/", "\\"); RemoveLauncherArgs(aspNetCoreElement); if (!isPortable) @@ -85,7 +84,19 @@ private static void TransformAspNetCore(XElement aspNetCoreElement, string appNa } SetAttributeValueIfEmpty(aspNetCoreElement, "stdoutLogEnabled", "false"); - SetAttributeValueIfEmpty(aspNetCoreElement, "stdoutLogFile", logPath); + + var logPath = Path.Combine(configureForAzure ? @"\\?\%home%\LogFiles" : @".\logs", "stdout").Replace("/", "\\"); + if (configureForAzure) + { + // When publishing for Azure we want to always overwrite path - the folder we set the path to + // will exist, the path is not easy to customize and stdoutLogPath should be only used for + // diagnostic purposes + aspNetCoreElement.SetAttributeValue("stdoutLogFile", logPath); + } + else + { + SetAttributeValueIfEmpty(aspNetCoreElement, "stdoutLogFile", logPath); + } } private static XElement GetOrCreateChild(XElement parent, string childName) diff --git a/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/WebConfigTransformFacts.cs b/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/WebConfigTransformFacts.cs index bc471ba76..d16314026 100644 --- a/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/WebConfigTransformFacts.cs +++ b/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/WebConfigTransformFacts.cs @@ -173,6 +173,17 @@ public void WebConfigTransform_correctly_configures_for_Azure() aspNetCoreElement)); } + [Fact] + public void WebConfigTransform_overwrites_stdoutLogPath_for_Azure() + { + var input = WebConfigTemplate; + var output = WebConfigTransform.Transform(input, "test.exe", configureForAzure: true, isPortable: false); + + Assert.Equal( + @"\\?\%home%\LogFiles\stdout", + (string)output.Descendants("aspNetCore").Single().Attribute("stdoutLogFile")); + } + [Fact] public void WebConfigTransform_configures_portable_apps_correctly() {