Implementing a logger provider for Blazor WASM #24697
Unanswered
ThomasArdal
asked this question in
General
Replies: 2 comments 4 replies
-
Anyone? |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to implement a logger provider for Blazor WASM. The provider requires a HTTP client to communicate with a remote API. The Blazor WASM documentation for adding new providers is very short and limited. Basically, it requires you to call:
In real life, you probably don't want to configure providers this way, since they need options and dependencies.
I have tried implementing my own custom logger provider for Blazor WASM, but I'm not sure if I'm missing something. As mentioned, it requires a HTTP client but also some options. Options class first:
Properties don't really matter for this example. Then an extension method on
ILoggingBuilder
to configure the new provider:The method register a new
HttpClient
, configure the options, and add the new logger provider as a singleton.The
ILoggerProvider
class looks like this:And finally the logger:
The new logger can now be configured like this:
Would this be a good way to implement a logger provider for Blazor WASM? I'm mostly thinking about the way I register the HTTP client and that the approach doesn't follow the documentation. Also, it would be great with some "official" examples of how to achieve this 👍
Beta Was this translation helpful? Give feedback.
All reactions