From 36d7c8ec4257f72507d2688a70b37ce660ef81d8 Mon Sep 17 00:00:00 2001 From: Justin Kotalik Date: Thu, 12 Jul 2018 16:03:06 -0700 Subject: [PATCH] Add startup event log for ANCM inproc (#1047) --- .../CommonLib/aspnetcore_msg.mc | 6 +++++ src/AspNetCoreModuleV2/CommonLib/resources.h | 1 + .../inprocessapplication.cpp | 5 ++++ .../Inprocess/EventLogTests.cs | 24 +++++++++++++++++++ .../Utilities/EventLogHelpers.cs | 18 ++++++++++++++ .../Utilities/Helpers.cs | 12 +++++++++- 6 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 test/Common.FunctionalTests/Inprocess/EventLogTests.cs create mode 100644 test/Common.FunctionalTests/Utilities/EventLogHelpers.cs diff --git a/src/AspNetCoreModuleV2/CommonLib/aspnetcore_msg.mc b/src/AspNetCoreModuleV2/CommonLib/aspnetcore_msg.mc index 13781f7c82..c15047b235 100644 --- a/src/AspNetCoreModuleV2/CommonLib/aspnetcore_msg.mc +++ b/src/AspNetCoreModuleV2/CommonLib/aspnetcore_msg.mc @@ -218,6 +218,12 @@ Language=English %1 . +Messageid=1032 +SymbolicName=ASPNETCORE_EVENT_INPROCESS_START_SUCCESS +Language=English +%1 +. + ; ;#endif // _ASPNETCORE_MODULE_MSG_H_ ; diff --git a/src/AspNetCoreModuleV2/CommonLib/resources.h b/src/AspNetCoreModuleV2/CommonLib/resources.h index 4620fa7e17..2956cce581 100644 --- a/src/AspNetCoreModuleV2/CommonLib/resources.h +++ b/src/AspNetCoreModuleV2/CommonLib/resources.h @@ -51,3 +51,4 @@ #define ASPNETCORE_EVENT_INVALID_PROCESS_PATH_MSG L"Invalid or unknown processPath provided in web.config: processPath = %s, ErrorCode = '0x%x'." #define ASPNETCORE_EVENT_INPROCESS_RH_MISSING_MSG L"Could not find the assembly '%s' for in-process application. Please confirm the Microsoft.AspNetCore.Server.IIS package is referenced in your application." #define ASPNETCORE_EVENT_OUT_OF_PROCESS_RH_MISSING_MSG L"Could not find the assembly '%s' for out-of-process application. Please confirm the assembly is installed correctly for IIS or IISExpress." +#define ASPNETCORE_EVENT_INPROCESS_START_SUCCESS_MSG L"Application '%s' started the coreclr in-process successfully." diff --git a/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp b/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp index ad0f6a35a6..bb56b01419 100644 --- a/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp +++ b/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp @@ -221,6 +221,11 @@ IN_PROCESS_APPLICATION::SetCallbackHandles( m_pLoggerProvider->NotifyStartupComplete(); // Can't check the std err handle as it isn't a critical error // Initialization complete + UTILITY::LogEventF(g_hEventLog, + EVENTLOG_INFORMATION_TYPE, + ASPNETCORE_EVENT_INPROCESS_START_SUCCESS, + ASPNETCORE_EVENT_INPROCESS_START_SUCCESS_MSG, + m_pConfig->QueryApplicationPhysicalPath()->QueryStr()); SetEvent(m_pInitalizeEvent); m_fInitialized = TRUE; } diff --git a/test/Common.FunctionalTests/Inprocess/EventLogTests.cs b/test/Common.FunctionalTests/Inprocess/EventLogTests.cs new file mode 100644 index 0000000000..1ae8aa5d57 --- /dev/null +++ b/test/Common.FunctionalTests/Inprocess/EventLogTests.cs @@ -0,0 +1,24 @@ +using System; +using System.Net; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities; +using Microsoft.AspNetCore.Testing.xunit; +using Xunit; + +namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests +{ + public class EventLogTests : IISFunctionalTestBase + { + [ConditionalFact] + public async Task CheckStartupEventLogMessage() + { + var deploymentParameters = Helpers.GetBaseDeploymentParameters(publish: true); + var deploymentResult = await DeployAsync(deploymentParameters); + await Helpers.AssertStarts(deploymentResult, "/HelloWorld"); + + StopServer(); + + EventLogHelpers.VerifyEventLogEvent(TestSink, "Application '.+' started the coreclr in-process successfully."); + } + } +} diff --git a/test/Common.FunctionalTests/Utilities/EventLogHelpers.cs b/test/Common.FunctionalTests/Utilities/EventLogHelpers.cs new file mode 100644 index 0000000000..1d53ba6843 --- /dev/null +++ b/test/Common.FunctionalTests/Utilities/EventLogHelpers.cs @@ -0,0 +1,18 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Text.RegularExpressions; +using Microsoft.Extensions.Logging.Testing; +using Xunit; + +namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests +{ + public class EventLogHelpers + { + public static void VerifyEventLogEvent(ITestSink testSink, string expectedRegexMatchString) + { + var eventLogRegex = new Regex($"Event Log: {expectedRegexMatchString}"); + Assert.Contains(testSink.Writes, context => eventLogRegex.IsMatch(context.Message)); + } + } +} diff --git a/test/Common.FunctionalTests/Utilities/Helpers.cs b/test/Common.FunctionalTests/Utilities/Helpers.cs index e68b3c8b67..e512dd6d83 100644 --- a/test/Common.FunctionalTests/Utilities/Helpers.cs +++ b/test/Common.FunctionalTests/Utilities/Helpers.cs @@ -4,9 +4,11 @@ using System; using System.IO; using System.Linq; +using System.Threading.Tasks; using System.Xml.Linq; using Microsoft.AspNetCore.Server.IntegrationTesting; using Microsoft.AspNetCore.Testing; +using Xunit; namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { @@ -60,7 +62,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests site = hostingModel == HostingModel.InProcess ? "InProcessWebSite" : "OutOfProcessWebSite"; } - return new DeploymentParameters(Helpers.GetTestWebSitePath(site), DeployerSelector.ServerType, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64) + return new DeploymentParameters(GetTestWebSitePath(site), DeployerSelector.ServerType, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64) { TargetFramework = Tfm.NetCoreApp22, ApplicationType = ApplicationType.Portable, @@ -73,5 +75,13 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests private static string GetWebConfigFile(IISDeploymentResult deploymentResult) => Path.Combine(deploymentResult.DeploymentResult.ContentRoot, "web.config"); + public static async Task AssertStarts(IISDeploymentResult deploymentResult, string path = "/HelloWorld") + { + var response = await deploymentResult.RetryingHttpClient.GetAsync(path); + + var responseText = await response.Content.ReadAsStringAsync(); + + Assert.Equal("Hello World", responseText); + } } }