Skip to content

Example of using NLog with CacheManager in .Net 5 #345

Answered by MichaCo
suntereo asked this question in Q&A
Discussion options

You must be logged in to vote

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…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@suntereo
Comment options

@suntereo
Comment options

@MichaCo
Comment options

@suntereo
Comment options

Answer selected by suntereo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants