Closed MarkStega closed 4 years ago
Where do you want your log messages to show up?
Startup.cs
, and inject and use ILogger
wherever you want (including in Blazor components)Blazor.Extensions.Logging.BrowserConsoleLogger
but would have to register it under a different interface (e.g., it could implement some new IBrowserLogger
interface) so that it doesn't clash with the normal server-side ILogger
.If you think I'm misunderstanding the question please let me know.
Update: BrowserConsoleLogger doesn't support server-side execution yet, because it relies on IJSInProcessRuntime
. I'd recommend this library be updated to use async interop rather than sync, as then it should just work.
@SteveSandersonMS
If you want them to be emitted to the server's log, then you don't need to do anything different from a normal server-side ASP.NET Core application. All the .NET is running on the server, so just configure your logging service in the server's DI Startup.cs, and inject and use ILogger wherever you want (including in Blazor components)
So obvious in retrospect and I am getting log messages as expected. The issue I raised was a 'red herring' and now that I have logging I see the issue ('@Inject HttpClient xyzzy' does not behave). I'll put it on gitter to start and if no joy will open an issue here.
I had tried SSR when 0.5 arrived and other than some dropping of the SignalR update path my application worked as it did on the client.
I just decided to try SSR again and the app fails. I suspect it is because the client is now filled (some say littered) with calls to Blazor.Extensions.Logging methods.
I thought (looking at the architecture diagram in the 0.5 announcement blog) that I could simply add the references to NLog as I do on the web server itself.
I started by removing this fragment
from ConfigureServices(IServiceCollection services)
I was immediately stymied when trying to add this fragment
to BlazorWebAssemblyHost.CreateDefaultBuilder just as I add it to WebHost.CreateDefaultBuilder in the web server program.cs
Is this an issue that the CreateDefaultBuilder has to have 'UseNLog()' added meaning that the NLog team (or I) need to write an extension to BlazorWebAssemblyHost.CreateDefaultBuilder?