✅ How to flush NLog on application exit with MEL
Hi, I am using Microsoft.Extension.Logger (MEL) ILogger abstraction, and NLog as my provided implementation.
When I use an AsyncWrapper, the final log messages aren't written. I've read that it's important to flush async targets before ending the application. How can I flush nlog via the MEL abstraction?
1 Reply
Bump, I'm still not sure the proper way to do this.
Nevermind, I've asked ChatGPT and it suggested that I dispose of the ILoggerFactory that I had created.
By updating my creation logic to store and reuse a single ILoggerFactory, then calling the _loggerFactory.Dispose function from within my managing class's dispose function, I am seeing that it is now flushed.
This was one case where some nudging of chatgpt and testing it's response actually helped.