Skip to content

Simplify customization of browser connection loggers - #54533

Merged
tmat merged 2 commits into
dotnet:release/10.0.4xxfrom
tmat:ConnectionLoggers
Jun 2, 2026
Merged

tmat merged 2 commits into
dotnet:release/10.0.4xxfrom
tmat:ConnectionLoggers

Conversation

@tmat

@tmat tmat commented Jun 1, 2026

Copy link
Copy Markdown
Member

Allow customization of connection related loggers without leaking dotnet-watch specific logger creation logic to consumers of Microsoft.Dotnet.Watch.Client source package.

@tmat
tmat requested a review from a team as a code owner June 1, 2026 16:16
Copilot AI review requested due to automatic review settings June 1, 2026 16:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ILoggerFactory usage with per-connection Func<int, ILogger> factories for browser connection “server” and “agent” loggers.
  • Moves browser connection ID assignment and “connected” logging into AbstractBrowserRefreshServer.
  • Updates dotnet-watch UI 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.

@tmat
tmat force-pushed the ConnectionLoggers branch from f66d635 to 42739b2 Compare June 1, 2026 18:54
@tmat

tmat commented Jun 2, 2026

Copy link
Copy Markdown
Member Author

@DustinCampbell ptal

@jonathanpeppers jonathanpeppers left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Just minor nit & question.


private static readonly JsonSerializerOptions s_jsonSerializerOptions = new(JsonSerializerDefaults.Web);

private static int s_lastConnectionId;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants