CmdPal: Wire up ILogger<T> in ShellViewModel and PowerToysRootPageService#46779
Draft
CmdPal: Wire up ILogger<T> in ShellViewModel and PowerToysRootPageService#46779
Conversation
…vice Agent-Logs-Url: https://github.com/microsoft/PowerToys/sessions/07d975df-d306-4734-8ba5-4b1f0784d79a Co-authored-by: crutkas <1462282+crutkas@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
crutkas
April 5, 2026 04:53
View session
Collaborator
|
@crutkas Hi, I pretty sure @michaeljolley has the folloup changes ready. I asked him to cheery-pick the logger registration, so could use it in a new code. |
Member
|
@jiripolasek and @michaeljolley this was me playing/learning. If it is done, 100% let’s close it out. If it can help the other PR, let’s cherry pick stuff in. |
Member
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of the Pull Request
Follow-up to #46768 which added the
CmdPalLogger/CmdPalLoggerProvider/AddCmdPalLogginginfrastructure with the explicit note: "This logging is not in use currently, but will be in a future PR."This is that future PR — it wires up
ILogger<T>injection in the two key DI-registered singleton services that previously used the old static logging patterns.Changes
Microsoft.CmdPal.UI.ViewModels.csprojMicrosoft.Extensions.Logging.Abstractionsas a directPackageReference(version already pinned inDirectory.Packages.props) so thatILogger<T>is available in the ViewModels project.ShellViewModel.csusing Microsoft.CmdPal.Common;(was only needed forCoreLogger)using Microsoft.Extensions.Logging;ILogger<ShellViewModel>as a new constructor parameter (last)CoreLogger.*calls with idiomatic MEL-style_logger.*calls:CoreLogger.LogError(ex.ToString())→_logger.LogError(ex, "…")with descriptive messages and proper exception propagationCoreLogger.LogError($"Failed to create ViewModel…")→_logger.LogError("…{PageType}", page.GetType().Name)(structured)CoreLogger.LogDebug(…)→_logger.LogDebug("…")PowerToysRootPageService.csusing ManagedCommon;(was only needed forLogger.*statics)using Microsoft.Extensions.Logging;ILogger<PowerToysRootPageService>as a new constructor parameter (last)Logger.LogError/Logger.LogWarning/ManagedCommon.Logger.LogErrorcalls with_logger.*equivalentsBoth services are registered as DI singletons via
services.AddSingleton<>()inApp.xaml.cs. BecauseAddCmdPalLogging()was already registered in the DI container by #46768, the newILogger<T>parameters are resolved automatically — no changes needed inApp.xaml.cs.PR Checklist