Setting up logging in Blazor #5604
Labels
area-blazor
Includes: Blazor, Razor Components
enhancement
This issue represents an ask for new feature or an enhancement to an existing one
Milestone
Hi all!! Hope you're all having fun, hacking on such an interesting bit of code 😄
I spent a few hours last night experimenting with Serilog in Blazor, both to the local browser console and piped through the server using middleware. The code is in: https://github.com/nblumhardt/serilog-blazor.
There's a whole lot to explore in this space, but I thought I'd try to get in early with a bit of feedback on how it hangs together.
Some developers, me among them, will go to great lengths to get logging set up before any other application code executes. This makes it easier to debug startup failures, which are usually critical issues. You can see I've done that in the Blazor client demo here: https://github.com/nblumhardt/serilog-blazor/blob/master/SerilogBlazorDemo.Client/Program.cs#L12
Because the demo pipes client logs through the server, HTTP is needed; getting the base URI before the Blazor host is initialized took some hackiness: https://github.com/nblumhardt/serilog-blazor/blob/master/SerilogBlazorDemo.Client/Diagnostics/BrowserHttpSink.cs#L67 - it would be great if this could be properly supported by the Blazor API.
This echoes some of the problems with logging in ASP.NET Core, particularly the decision to put configuration (and thus logging setup) into DI. This ends up greatly expanding the amount of code that runs before logging is available, and thus the scope of potential failures that can't be properly logged. It would be great to avoid this in Blazor, by providing non-DI access to critical system services (like HTTP, mentioned above). Less-ergonomics/jumping-through-hoops would be acceptable, if it enabled bootstrapping logging ahead of anything else.
Hope this is at least food-for-thought, and good luck with it all! (Also, hope you have a chance to run the demo, it's quite compelling to see just how consistent the client/server experiences can be 😎 .)
The text was updated successfully, but these errors were encountered: