From 31a6a126e38e21eb045e6817c85f5c40a078cbbf Mon Sep 17 00:00:00 2001 From: moozzyk Date: Mon, 30 May 2016 22:15:14 -0700 Subject: [PATCH] Always overwrite stdoutLogPath when publishing for Azure Addresses #167 --- .../WebConfigTransform.cs | 15 +++++++++++++-- .../WebConfigTransformFacts.cs | 11 +++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/WebConfigTransform.cs b/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/WebConfigTransform.cs index 563e2a00eb..1db5cc8c8e 100644 --- a/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/WebConfigTransform.cs +++ b/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/WebConfigTransform.cs @@ -60,7 +60,6 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools // 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 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools } 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 bc471ba766..d163140260 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 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests 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() {