Repository navigation
Simplify customization of browser connection loggers - #54533
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the browser refresh/hot reload client logging pipeline so consumers can customize per-connection loggers without depending on dotnet-watch’s internal logger factory patterns.
Changes:
- Replaces
ILoggerFactoryusage with per-connectionFunc<int, ILogger>factories for browser connection “server” and “agent” loggers. - Moves browser connection ID assignment and “connected” logging into
AbstractBrowserRefreshServer. - Updates
dotnet-watchUI component emoji mapping and unit test utilities to match the new logging API shape.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/dotnet-watch.Tests/TestUtilities/TestBrowserRefreshServer.cs | Updates test server to pass per-connection logger factories instead of an ILoggerFactory. |
| src/Dotnet.Watch/Watch/UI/IReporter.cs | Updates component-to-emoji mapping to use new constants. |
| src/Dotnet.Watch/Watch/AppModels/WebApplicationAppModel.cs | Introduces component name constants and wires up browser refresh server creation with per-connection logger factories. |
| src/Dotnet.Watch/HotReloadClient/Web/IBrowserConnectionLoggerFactory.cs | Adds a (currently unused) interface intended to represent connection logger creation. |
| src/Dotnet.Watch/HotReloadClient/Web/BrowserRefreshServer.cs | Updates constructor/base call to accept per-connection logger factories. |
| src/Dotnet.Watch/HotReloadClient/Web/BrowserConnection.cs | Refactors connection to accept ID and loggers from the server instead of creating them internally. |
| src/Dotnet.Watch/HotReloadClient/Web/AbstractBrowserRefreshServer.cs | Adds per-connection logger factories; assigns connection IDs and emits “connected” logging here. |
Harden OnBrowserConnected
|
@DustinCampbell ptal |
jonathanpeppers
left a comment
There was a problem hiding this comment.
Looks good to me. Just minor nit & question.
|
|
||
| private static readonly JsonSerializerOptions s_jsonSerializerOptions = new(JsonSerializerDefaults.Web); | ||
|
|
||
| private static int s_lastConnectionId; |
There was a problem hiding this comment.
Just curious, but this puts static state inside an abstract class, so process-wide.
Does it actually need to be static? Could each instance of the browser server have its own counter?
There was a problem hiding this comment.
It does not need to be static. The number is used to identify browser in a log message uniquely. I think it's easier to read the logs if each browser has globally unique number. It was not unique you'd need to check which project is the particular browser associated with.
Allow customization of connection related loggers without leaking dotnet-watch specific logger creation logic to consumers of Microsoft.Dotnet.Watch.Client source package.