-
I cannot seem to get NLog working with CacheManager 2.0 PR. Here is the info I'd love to log with NLog:
At best, I can only get this info to log to console. Here's my Program.cs:
And here is where I identity the logger for CacheManager:
The above logs to console, but not via NLog and so my NLog target (Graylog) never receives this info. I cannot seem to get cfg.WithLogging() working with any Type. CacheReflectionHelper always fails this check:
For example, if I do:
Then I get: I'm guessing I'm just not passing the correct object. But what do I pass for NLog here? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
I guess it depends when your code to get the ILoggerFactory from the services collection runs. cfg.WithLogging only accepts, implementations CacheManager's ILoggerFactory interface. :edit: Had to move UseNLog to run before configure services. That's still a bit fishy, because I still have to build the services collection and then am just lucky to get the right instance of the LoggerFactory ~~.
By looking into the code what the UseNLog extension is doing, I found that they in the end call |
Beta Was this translation helpful? Give feedback.
I guess it depends when your code to get the ILoggerFactory from the services collection runs.
If NLog creates a new Microsoft.Exntesions.Logging ILoggerFactory somewhere, then you might get one which was created beforehand.
Best would be to inject ILoggerFactory to the ctor of your startup and then pass that to cfg.WithMicrosoftLogging
cfg.WithLogging only accepts, implementations CacheManager's ILoggerFactory interface.
That's the pain with abstractions ;)
:edit:
@suntereo I got it working with the HostingExample app from here: https://github.com/NLog/NLog.Extensions.Logging/tree/master/examples/NetCore2
Had to move UseNLog to run before configure services. That's still a bit fishy, bec…