diff --git a/src/AppInstallerCLICore/COMContext.cpp b/src/AppInstallerCLICore/COMContext.cpp index 4a867f6051..2eae8694d7 100644 --- a/src/AppInstallerCLICore/COMContext.cpp +++ b/src/AppInstallerCLICore/COMContext.cpp @@ -75,10 +75,10 @@ namespace AppInstaller::CLI::Execution return m_correlationData; } - void COMContext::SetLoggers() + void COMContext::SetLoggers(std::optional channel, std::optional level) { - Logging::Log().EnableChannel(Settings::User().Get()); - Logging::Log().SetLevel(Settings::User().Get()); + Logging::Log().EnableChannel(channel.has_value() ? channel.value() : Settings::User().Get()); + Logging::Log().SetLevel(level.has_value() ? level.value() : Settings::User().Get()); // TODO: Log to file for COM API calls only when debugging in visual studio Logging::FileLogger::Add(s_comLogFileNamePrefix); diff --git a/src/AppInstallerCLICore/COMContext.h b/src/AppInstallerCLICore/COMContext.h index 472907d76e..9e4d136a52 100644 --- a/src/AppInstallerCLICore/COMContext.h +++ b/src/AppInstallerCLICore/COMContext.h @@ -66,7 +66,7 @@ namespace AppInstaller::CLI::Execution // Set Diagnostic and Telemetry loggers, Wil failure callback // This should be called only once per COM Server instance - static void SetLoggers(); + static void SetLoggers(std::optional channel = std::nullopt, std::optional level = std::nullopt); // Set COM call context for diagnostic and telemetry loggers // This should be called for every COMContext object instance diff --git a/src/AppInstallerCLICore/Core.cpp b/src/AppInstallerCLICore/Core.cpp index 418c326016..4f92ce39f9 100644 --- a/src/AppInstallerCLICore/Core.cpp +++ b/src/AppInstallerCLICore/Core.cpp @@ -179,5 +179,18 @@ namespace AppInstaller::CLI #endif AppInstaller::CLI::Execution::COMContext::SetLoggers(); + } + + void InProcInitialize() + { +#ifndef AICLI_DISABLE_TEST_HOOKS + if (Settings::User().Get()) + { + Debugging::EnableSelfInitiatedMinidump(); + } +#endif + + // Explicitly set default channel and level before user settings from PackageManagerSettings + AppInstaller::CLI::Execution::COMContext::SetLoggers(AppInstaller::Logging::Channel::Defaults, AppInstaller::Logging::Level::Info); } } diff --git a/src/AppInstallerCLICore/Public/AppInstallerCLICore.h b/src/AppInstallerCLICore/Public/AppInstallerCLICore.h index e93643442f..9353b3beef 100644 --- a/src/AppInstallerCLICore/Public/AppInstallerCLICore.h +++ b/src/AppInstallerCLICore/Public/AppInstallerCLICore.h @@ -9,4 +9,7 @@ namespace AppInstaller::CLI // Initializes the Windows Package Manager COM server. void ServerInitialize(); + + // Initializations for InProc invocation. + void InProcInitialize(); } diff --git a/src/Microsoft.Management.Deployment/PackageManagerSettings.cpp b/src/Microsoft.Management.Deployment/PackageManagerSettings.cpp index 9b76a9d8e8..11ba9b99d5 100644 --- a/src/Microsoft.Management.Deployment/PackageManagerSettings.cpp +++ b/src/Microsoft.Management.Deployment/PackageManagerSettings.cpp @@ -48,6 +48,11 @@ namespace winrt::Microsoft::Management::Deployment::implementation [&]() { success = AppInstaller::Settings::TryInitializeCustomUserSettings(AppInstaller::Utility::ConvertToUTF8(settingsContent)); + if (success) + { + AppInstaller::Logging::Log().EnableChannel(AppInstaller::Settings::User().Get()); + AppInstaller::Logging::Log().SetLevel(AppInstaller::Settings::User().Get()); + } }); return success; } diff --git a/src/WindowsPackageManager/main.cpp b/src/WindowsPackageManager/main.cpp index 37414f42ac..609735d86c 100644 --- a/src/WindowsPackageManager/main.cpp +++ b/src/WindowsPackageManager/main.cpp @@ -86,6 +86,7 @@ extern "C" WINDOWS_PACKAGE_MANAGER_API WindowsPackageManagerInProcModuleInitialize() try { ::Microsoft::WRL::Module<::Microsoft::WRL::ModuleType::InProc>::Create(); + AppInstaller::CLI::InProcInitialize(); return S_OK; } CATCH_RETURN();