Blazor wasm signalr client logging doesn't exist
See original GitHub issueDescribe the bug
There is currently no documented, working, simple, way to add signalr logging to a .NET client running in blazor-wasm.
The tutorial Use ASP.NET Core SignalR with Blazor WebAssembly
implies that this is a supported workflow, and the Logging and diagnostics page provides the instructions for the .NET client used in the tutorial. However, on attempting to follow these instructions, a System.NotSupportedException: Cannot start threads on this runtime
stack trace is produced and the application crashes.
Workarounds: I’ve attempted to work around this by using Blazor.Extensions.Logging but this doesn’t seem to work as the provider is internal. I’ve tried to create a custom provider, but gave up after an hour.
Am I missing something really obvious? Shouldn’t simple logging be working out of the box?
To Reproduce
I’ve created a repro in https://github.com/tboby/blazor-wasm-signalr-logging
master: The tutorial code, with up to date packages and css (so it actually builds).
signalr-logging-tutorial: A single commit with the modification as recommended in the documentation, and in issue #22687 .
- Clone the repo
- Checkout master
- Run the Server project and see that the tutorial project works
- Checkout signal-logging-tutorial
- Run the Server project and see the browser console for the stack trace
Exceptions (if any)
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Cannot start threads on this runtime.
System.NotSupportedException: Cannot start threads on this runtime.
at (wrapper managed-to-native) System.Reflection.RuntimeConstructorInfo.InternalInvoke(System.Reflection.RuntimeConstructorInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) <0x264d878 + 0x0001e> in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor (Microsoft.Extensions.DependencyInjection.ServiceLookup.ConstructorCallSite constructorCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context) <0x28bbff0 + 0x00108> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[TArgument,TResult].VisitCallSiteMain (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, TArgument argument) <0x2855838 + 0x000a8> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope serviceProviderEngine, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverLock lockType) <0x28b9278 + 0x000ce> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite singletonCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context) <0x28b8ea0 + 0x0002e> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[TArgument,TResult].VisitCallSite (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, TArgument argument) <0x2852f90 + 0x000a6> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerable (Microsoft.Extensions.DependencyInjection.ServiceLookup.IEnumerableCallSite enumerableCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context) <0x28bc3a0 + 0x00056> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[TArgument,TResult].VisitCallSiteMain (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, TArgument argument) <0x2855838 + 0x00082> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope serviceProviderEngine, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverLock lockType) <0x28b9278 + 0x000ce> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite singletonCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context) <0x28b8ea0 + 0x0002e> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[TArgument,TResult].VisitCallSite (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, TArgument argument) <0x2852f90 + 0x000a6> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor (Microsoft.Extensions.DependencyInjection.ServiceLookup.ConstructorCallSite constructorCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context) <0x28bbff0 + 0x00072> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[TArgument,TResult].VisitCallSiteMain (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, TArgument argument) <0x2855838 + 0x000a8> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope serviceProviderEngine, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverLock lockType) <0x28b9278 + 0x000ce> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite singletonCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context) <0x28b8ea0 + 0x0002e> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[TArgument,TResult].VisitCallSite (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, TArgument argument) <0x2852f90 + 0x000a6> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor (Microsoft.Extensions.DependencyInjection.ServiceLookup.ConstructorCallSite constructorCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context) <0x28bbff0 + 0x00072> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[TArgument,TResult].VisitCallSiteMain (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, TArgument argument) <0x2855838 + 0x000a8> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope serviceProviderEngine, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverLock lockType) <0x28b9278 + 0x000ce> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite singletonCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context) <0x28b8ea0 + 0x0002e> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[TArgument,TResult].VisitCallSite (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, TArgument argument) <0x2852f90 + 0x000a6> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope scope) <0x28529e8 + 0x0002c> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine+<>c__DisplayClass1_0.<RealizeService>b__0 (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope scope) <0x2852800 + 0x00062> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope serviceProviderEngineScope) <0x2846c40 + 0x0006c> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService (System.Type serviceType) <0x2838228 + 0x0000e> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService (System.Type serviceType) <0x28380d8 + 0x0000e> in <filename unknown>:0
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T] (System.IServiceProvider provider) <0x2d60958 + 0x00022> in <filename unknown>:0
at Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilder.Build () <0x2d60858 + 0x00030> in <filename unknown>:0
at BlazorSignalRApp.Client.Pages.Index.OnInitializedAsync () [0x00012] in C:\Users\Thomas\Git\blazor-wasm-signalr-logging\Client\Pages\Index.razor:37
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync () <0x2c1fde0 + 0x0013a> in <filename unknown>:0
Further technical details
ASP.NET Core version: 3.2.0, see project file https://github.com/tboby/blazor-wasm-signalr-logging/blob/signalr-logging-tutorial/Client/BlazorSignalRApp.Client.csproj
.NET Core SDK (reflecting any global.json):
Version: 3.1.300
Commit: b2475c1295
Runtime Environment:
OS Name: Windows
OS Version: 10.0.18363
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.300\
Host (useful for support):
Version: 3.1.4
Commit: 0c2e69caa6
.NET Core SDKs installed:
3.0.100 [C:\Program Files\dotnet\sdk]
3.1.102 [C:\Program Files\dotnet\sdk]
3.1.300 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Using VS Enterprise 16.6.1, but can reproduce with dotnet run
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
@mkArtakMSFT Sorry, again, but I don’t see how that helps in this situation. I think I’ve worked out how to do it, see below.
This is not documented at all, and the current documentation doesn’t work.
@mandalorianbob I think I might have found the solution though!
@inject ILoggerProvider loggingprovider;
I think this issue is still valid, as the documentation is incorrect, and worse, leads users down a rabbit hole of irrelevant configuration.
Perhaps. The issue seems to be a disconnect in the docs that the SignalR tutorial provides on logging and what we currently support.
The SignalR logging docs (ref) assumes that you are running in a .NET client on the server but when running in Blazor, we need to inject the WebAssemblyConsoleLoggerProvider so that the logs show up correctly in the browser console.
@guardrex Perhaps we can write a brief snippet on this in the logging docs?