Adding HttpPlatformHandler logging defaults to web.config

- writing a default path to log file if one does not exist
 - setting stdoutLogEnabled to false if the attribute does not exist
This commit is contained in:
moozzyk 2016-01-19 16:51:26 -08:00
parent 31f4b41a2e
commit 674efca4de
2 changed files with 54 additions and 1 deletions

View File

@ -59,6 +59,7 @@ namespace Microsoft.AspNetCore.Tools.PublishIIS
{
httpPlatformElement.SetAttributeValue("processPath", Path.Combine("..", appName));
SetAttributeValueIfEmpty(httpPlatformElement, "stdoutLogEnabled", "false");
SetAttributeValueIfEmpty(httpPlatformElement, "stdoutLogFile", @"..\logs\stdout.log");
SetAttributeValueIfEmpty(httpPlatformElement, "startupTimeLimit", "3600");
}

View File

@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Tools.PublishIIS.Tests
<handlers>
<add name=""httpPlatformHandler"" path=""*"" verb=""*"" modules=""httpPlatformHandler"" resourceType=""Unspecified""/>
</handlers>
<httpPlatform processPath=""..\test.exe"" stdoutLogEnabled=""false"" startupTimeLimit=""3600""/>
<httpPlatform processPath=""..\test.exe"" stdoutLogEnabled=""false"" stdoutLogFile=""..\logs\stdout.log"" startupTimeLimit=""3600""/>
</system.webServer>
</configuration>");
@ -96,6 +96,58 @@ namespace Microsoft.AspNetCore.Tools.PublishIIS.Tests
WebConfigTransform.Transform(input, "app.exe").Descendants("httpPlatform").Elements().Single()));
}
[Fact]
public void WebConfigTransform_adds_stdoutLogEnabled_if_attribute_is_missing()
{
var input = new XDocument(WebConfigTemplate);
input.Descendants("httpPlatform").Attributes("stdoutLogEnabled").Remove();
Assert.Equal(
"false",
(string)WebConfigTransform.Transform(input, "test.exe").Descendants().Attributes("stdoutLogEnabled").Single());
}
[Theory]
[InlineData(null)]
[InlineData("false")]
[InlineData("true")]
public void WebConfigTransform_adds_stdoutLogFile_if_attribute_is_missing(string stdoutLogFile)
{
var input = new XDocument(WebConfigTemplate);
var httpPlatformElement = input.Descendants("httpPlatform").Single();
httpPlatformElement.Attribute("stdoutLogEnabled").Remove();
if (stdoutLogFile != null)
{
httpPlatformElement.SetAttributeValue("stdoutLogEnabled", stdoutLogFile);
}
Assert.Equal(
@"..\logs\stdout.log",
(string)WebConfigTransform.Transform(input, "test.exe").Descendants().Attributes("stdoutLogFile").Single());
}
[Theory]
[InlineData(null)]
[InlineData("true")]
[InlineData("false")]
public void WebConfigTransform_does_not_change_existing_stdoutLogEnabled(string stdoutLogEnabledValue)
{
var input = new XDocument(WebConfigTemplate);
var httpPlatformElement = input.Descendants("httpPlatform").Single();
httpPlatformElement.SetAttributeValue("stdoutLogFile", "mylog.txt");
httpPlatformElement.Attributes("stdoutLogEnabled").Remove();
if (stdoutLogEnabledValue != null)
{
input.Descendants("httpPlatform").Single().SetAttributeValue("stdoutLogEnabled", stdoutLogEnabledValue);
}
Assert.Equal(
"mylog.txt",
(string)WebConfigTransform.Transform(input, "test.exe").Descendants().Attributes("stdoutLogFile").Single());
}
private bool VerifyMissingElementCreated(params string[] elementNames)
{
var input = new XDocument(WebConfigTemplate);