Yes, I only have one logger instance created within my hosted service, but there are also other loggers instantiated namely the standard loggers of the MS-hosted server.
I may also have multiple logger providers in my project in the future, but I only have to acces the one with the memory.
However, I checked, what's in the logger instance. There are 3 Logger arrays:
- Loggers (of type LoggerInformation)
- MessageLoggers (of type MessageLogger)
- ScopeLoggers (of type ScopeLogger)
Within the Loggers I have 6 items, which I think, are the loggers of the project, also built ins like console logger, debug logger, etc.
Within the MessageLoggers, I also have 6 loggers, however, I could find myLoggerProvider in this list.
ScopeLoggers are for Scope, however, I also find my provider in that list, as I use scope.
That's, OK
But as these properties are not accessable by standard, I should use reflection to access it as well as I have to loop through all items to find MyLoggerProvider.
Do you have an idea if there is another, simpler way to access MyLogerProvider?
Eg. I have to use the right type of _logger to make these properties accessible.
Here are the quickwatch windows:
In _logger I have 3 arrays:
If I open the Loggers, there are 6 elements of LoggerInformation:
There I can find MyLoggerProvider in the 4th indexed element:
But I can also open the MessageLoggers with also 6 elements of type MessageLogger in it:
And the MyLoggerProvider is in the 4th indexed element again, accessible by Logger:
Should I now access MyLoggerProvider by Loggers-LoggerInformation or by MessageLoggers-MessageLogger ?
Which one is better ?
I see, that the instantiated type of _logger is Microsoft.Extensions.Logging.Logger, but if I want to cast it to that type, the development system requests Microsoft.Extensions.Logging.Logger<> as generic. The instantiated type is not generic, so I cannot cast.
So how can I access the properties ?
However, I can use reflection to get it, but accessing by type is even better.
Or is there a way by dependency injection ?