SignalR TypeScript Client -HubConnectionBuilder - ILogger is not replaced when using build()
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Describe the bug
When using the SignalR clients HubConnectionBuilder, under certain circumstances the configured ILogger is ignored.
### To Reproduce
```ts
const hubConnectionBuilder = new HubConnectionBuilder();
....
const hubConnection1: signalR.HubConnection = this.hubConnectionBuilder
.withUrl(..., { ... })
.configureLogging(new Logger(...))
.build();
const hubConnection2: signalR.HubConnection = this.hubConnectionBuilder
.withUrl(..., { ... }),
.configureLogging(new Logger(...))
.build();
```
In this scenario the logger configured for the first connection will be reused for the second one.
```ts
const hubConnectionBuilder = new HubConnectionBuilder();
....
const hubConnection1: signalR.HubConnection = this.hubConnectionBuilder
.withUrl(..., { ..., logger: new Logger(...) })
.build();
const hubConnection2: signalR.HubConnection = this.hubConnectionBuilder
.withUrl(..., { ..., logger: new Logger(...) })
.build();
```
In this scenario the logger configured for the first connection will be different than the one configured for the second connection.
It has to do with these lines:
https://github.com/dotnet/aspnetcore/blob/c440ebcf49badd49f0e2cdde1b0a74992af04158/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts#L130-L137
https://github.com/dotnet/aspnetcore/blob/c440ebcf49badd49f0e2cdde1b0a74992af04158/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts#L196-L199
Since a previous connection was created, the **httpConnectionOptions**will be populated with the previous logger. Since this logger is already configured, explicitly configuring a new one will fail because the only situation in which the logger is assigned is if the **httpConnectionOptions** had no log configured. However, since the previous **httpConnectionOptions**are combined into the new ones when **withUrl** is used, then it is not possible to change the logger anymore.
Contributor guide
Assessment
This issue has not been assessed yet.