commit f6e453e3d398c08929cd824394bcf1c09acb4ca0
parent b82746e3533b8ee800247e40390995f3b44741d3
Author: JohnMcPMS <johnmcp@microsoft.com>
Date: Tue, 25 Jul 2023 08:44:30 -0700
Add file logger to the statics object creation (#3451)
Add a file logger for the factory creation (and anything else we wanted to log in the statics object), which isn't covered by any other logging/diagnostics.
Diffstat:
2 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/src/Microsoft.Management.Configuration.OutOfProc/Prepare-ConfigurationOOPTests.ps1 b/src/Microsoft.Management.Configuration.OutOfProc/Prepare-ConfigurationOOPTests.ps1
@@ -20,13 +20,16 @@ $Local:dllTargetPath = Join-Path $BuildOutputPath "Microsoft.Management.Configur
Copy-Item $Local:dllSourcePath $Local:dllTargetPath -Force
# Register the package
-$Local:packageManifestPath = Join-Path $PackageLayoutPath "AppxManifest.xml"
+if (-not [System.String]::IsNullOrEmpty($PackageLayoutPath))
+{
+ $Local:packageManifestPath = Join-Path $PackageLayoutPath "AppxManifest.xml"
-Add-AppxPackage -Register $Local:packageManifestPath
+ Add-AppxPackage -Register $Local:packageManifestPath
-# Configure crash dump and log file settings
-$Local:settingsExport = ConvertFrom-Json (wingetdev.exe settings export)
-$Local:settingsFilePath = $Local:settingsExport.userSettingsFile
-$Local:settingsFileContent = ConvertTo-Json @{ debugging= @{ enableSelfInitiatedMinidump=$true ; keepAllLogFiles=$true } }
+ # Configure crash dump and log file settings
+ $Local:settingsExport = ConvertFrom-Json (wingetdev.exe settings export)
+ $Local:settingsFilePath = $Local:settingsExport.userSettingsFile
+ $Local:settingsFileContent = ConvertTo-Json @{ debugging= @{ enableSelfInitiatedMinidump=$true ; keepAllLogFiles=$true } }
-Set-Content -Path $Local:settingsFilePath -Value $Local:settingsFileContent
+ Set-Content -Path $Local:settingsFilePath -Value $Local:settingsFileContent
+}
diff --git a/src/WindowsPackageManager/ConfigurationStaticFunctions.cpp b/src/WindowsPackageManager/ConfigurationStaticFunctions.cpp
@@ -5,12 +5,14 @@
#include <winrt/Microsoft.Management.Configuration.h>
#include <ComClsids.h>
#include <AppInstallerErrors.h>
+#include <AppInstallerFileLogger.h>
#include <AppInstallerStrings.h>
#include <winget/ConfigurationSetProcessorHandlers.h>
#include <ConfigurationSetProcessorFactoryRemoting.h>
#include <winget/ILifetimeWatcher.h>
#include <winget/GroupPolicy.h>
#include <winget/Security.h>
+#include <winget/ThreadGlobals.h>
namespace ConfigurationShim
{
@@ -26,7 +28,14 @@ namespace ConfigurationShim
DECLSPEC_UUID(WINGET_OUTOFPROC_COM_CLSID_ConfigurationStaticFunctions)
ConfigurationStaticFunctionsShim : winrt::implements<ConfigurationStaticFunctionsShim, winrt::Microsoft::Management::Configuration::IConfigurationStatics>
{
- ConfigurationStaticFunctionsShim() = default;
+ ConfigurationStaticFunctionsShim()
+ {
+ auto threadGlobalsRestore = m_threadGlobals.SetForCurrentThread();
+ auto& diagnosticsLogger = m_threadGlobals.GetDiagnosticLogger();
+ diagnosticsLogger.EnableChannel(AppInstaller::Logging::Channel::All);
+ diagnosticsLogger.SetLevel(AppInstaller::Logging::Level::Verbose);
+ diagnosticsLogger.AddLogger(std::make_unique<AppInstaller::Logging::FileLogger>("ConfigStatics"sv));
+ }
winrt::Microsoft::Management::Configuration::ConfigurationUnit CreateConfigurationUnit()
{
@@ -49,6 +58,7 @@ namespace ConfigurationShim
co_await winrt::resume_background();
+ auto threadGlobalsRestore = m_threadGlobals.SetForCurrentThread();
winrt::Microsoft::Management::Configuration::IConfigurationSetProcessorFactory result;
if (lowerHandler == AppInstaller::Configuration::PowerShellHandlerIdentifier)
@@ -88,6 +98,7 @@ namespace ConfigurationShim
}
winrt::Microsoft::Management::Configuration::ConfigurationStaticFunctions m_statics;
+ AppInstaller::ThreadLocalStorage::WingetThreadGlobals m_threadGlobals;
};
// Enable custom code to run before creating any object through the factory.