doc/devdocs/development/logging.md
PowerToys has several types of logging mechanisms:
%LOCALAPPDATA%\Microsoft\PowerToys\Logs%USERPROFILE%/AppData/LocalLow/Microsoft/PowerToysIn C++ projects we use the awesome spdlog library for logging as a git submodule under the deps directory. To use it in your project, just include spdlog.props in a .vcxproj like this:
<Import Project="..\..\..\deps\spdlog.props" />
It'll add the required include dirs and link the library binary itself.
init_logger();
For C# projects there is a static logger class in Managed Common called Logger.
To use it, add a project reference to ManagedCommon and add the following line of code to all the files using the logger:
using ManagedCommon;
In the Main function (or a function with a similar meaning (like App in a App.xaml.cs file)) you have to call InitializeLogger and specify the location where the logs will be saved (always use a path scheme similar to this example):
Logger.InitializeLogger("\\FancyZones\\Editor\\Logs");
For a low-privilege process you have to set the optional second parameter to true:
Logger.InitializeLogger("\\FileExplorer\\Monaco\\Logs", true);
The Logger class contains the following logging functions:
// Logs an error that the utility encountered
Logger.LogError(string message);
Logger.LogError(string message, Exception ex);
// Logs an error that isn't that grave
Logger.LogWarning(string message);
// Logs what the app is doing at the moment
Logger.LogInfo(string message);
// Like LogInfo just with infos important for debugging
Logger.LogDebug(string message);
// Logs the current state of the utility.
Logger.LogTrace();
Trace::AlwaysOnTop::Enable(true);
PowerToysTelemetry.Log.WriteEvent(new LauncherShowEvent(hotKey));
%LOCALAPPDATA%\Microsoft\PowerToys\ETL (for most utilities)The BugReportTool can be triggered via:
It creates a zip file on desktop named "PowerToys_Report_[date]_[time].zip" containing logs and system information.
See Bug Report Tool for more detailed information about the tool.