如果应用程序异常崩溃/关闭,则在具有数据库目标的BufferingWrapper之上的Nlog AutoFlushWrapper将丢失缓冲区中的日志

时间:2018-04-09 11:14:22

标签: .net nlog

我在Nlog AutoFlushWrapper之上AutoFlushWrapper使用database目标与fallbackfile目标,目前我的缓冲区大小为{{1}和50一起到2分钟但是如果应用程序异常崩溃/关闭,那么缓冲区中的日志就不会被记录。

例如,Nlog在缓冲区和应用程序崩溃中有flushtimeout个日志,然后这些日志没有被刷新。

有人可以帮助我吗?

以下是代码的小片段

10

1 个答案:

答案 0 :(得分:1)

  

如果应用程序异常崩溃/关闭,则不会记录缓冲区中的日志。

让程序自身崩溃听起来有点不受欢迎,但它会在NLog.LogManager.Shutdown();中推荐finally

e.g。

class Program
{
    static void Main(string[] args)
    {
        try
        {
            //do something
        }

        finally
        {
            // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
            NLog.LogManager.Shutdown();
        }
    }
}