I have a program which crashes unexpetedly. I have put NLog to provide me information about where it crashes but it doesn't achieve its goal for it logs up to 30" before the crash. So I have to change something.
I have seen that there should the command NFlush from here but as a matter of fact there isn't
I have version 4.7.10.
But if it was I might use in some strategic points.
So my questions are: how to flush? And is there instead another way to make NLog flush more frequently?
Thanks
Patrick
The screenshot with intellisense-suggestions comes from the NLog Logger-object. The NLog.LogManager.Flush() is a static-method.
NLog automatically attempts to flush when being notified that application is about to exit. This is done by hooking into both AppDomain.ProcessExit + AppDomain.DomainUnload
This automatic flush/shutdown usually works okay on .NetFramework running on Windows. But when running on other platforms using NetCore, then the AppDomain-events can be fired very early before the application has even started to shutdown. Thus causing NLog to stop logging while application is still in progress of shutting down. Microsoft seems to be working on improving this behavior, but not sure if Net60 will include the fixes. NLog.LogManager.AutoShutdown = false tells NLog that the user will explictly handle flush/shutdown.
The simple solution is just to use NLog FileTarget or NLog ConsoleTarget (they flush automatically), and without using <targets async="true">. And if running on exotic platforms, where Microsoft have failed to implement correct signal of process-exit, then configure NLog.LogManager.AutoShutdown = false.