From d2c31edc14d3566336ea7f0882865f81d59b2aff Mon Sep 17 00:00:00 2001 From: Justin Kotalik Date: Wed, 2 Sep 2020 15:54:41 -0700 Subject: [PATCH] Improving logs from hostfxr (#25541) --- .../inprocessapplication.cpp | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp b/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp index 1dd8a42c4b..8643f8089a 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp @@ -251,10 +251,26 @@ IN_PROCESS_APPLICATION::ExecuteApplication() LOG_INFOF(L"Setting current directory to %s", this->QueryApplicationPhysicalPath().c_str()); } + auto redirectionOutput = LoggingHelpers::CreateOutputs( + m_pConfig->QueryStdoutLogEnabled(), + m_pConfig->QueryStdoutLogFile(), + QueryApplicationPhysicalPath(), + m_stringRedirectionOutput + ); + + StandardStreamRedirection redirection(*redirectionOutput.get(), m_pHttpServer.IsCommandLineLaunch()); + + context->m_redirectionOutput = redirectionOutput.get(); + + ForwardingRedirectionOutput redirectionForwarder(&context->m_redirectionOutput); + const auto redirect = context->m_hostFxr.RedirectOutput(&redirectionForwarder); + auto startupReturnCode = context->m_hostFxr.InitializeForApp(context->m_argc, context->m_argv.get(), m_dotnetExeKnownLocation); if (startupReturnCode != 0) { - throw InvalidOperationException(format(L"Error occurred when initializing in-process application, Return code: 0x%x", startupReturnCode)); + auto content = m_stringRedirectionOutput->GetOutput(); + + throw InvalidOperationException(format(L"Error occurred when initializing in-process application, Return code: 0x%x, Error logs: %ls", startupReturnCode, content.c_str())); } if (m_pConfig->QueryCallStartupHook()) @@ -280,17 +296,6 @@ IN_PROCESS_APPLICATION::ExecuteApplication() bool clrThreadExited; { - auto redirectionOutput = LoggingHelpers::CreateOutputs( - m_pConfig->QueryStdoutLogEnabled(), - m_pConfig->QueryStdoutLogFile(), - QueryApplicationPhysicalPath(), - m_stringRedirectionOutput - ); - - StandardStreamRedirection redirection(*redirectionOutput.get(), m_pHttpServer.IsCommandLineLaunch()); - - context->m_redirectionOutput = redirectionOutput.get(); - //Start CLR thread m_clrThread = std::thread(ClrThreadEntryPoint, context); @@ -480,8 +485,6 @@ IN_PROCESS_APPLICATION::ClrThreadEntryPoint(const std::shared_ptrm_errorWriter itself to be able to // disconnect listener before CLR exits - ForwardingRedirectionOutput redirectionForwarder(&context->m_redirectionOutput); - const auto redirect = context->m_hostFxr.RedirectOutput(&redirectionForwarder); ExecuteClr(context); }