c# – 如何检查NLog是否已在异步模式下从队列中记录消息?
发布时间:2020-12-15 21:03:13 所属栏目:百科 来源:网络整理
导读:我有一个NLog配置文件如下.由于某些原因,NLog需要进行异步处理. nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true" targets async="true" target name="file" xsi:type=
我有一个NLog配置文件如下.由于某些原因,NLog需要进行异步处理.
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true"> <targets async="true"> <target name="file" xsi:type="File" fileName="c:/log1.log" archiveEvery="Day" archiveNumbering="Rolling"/> </targets> <rules> <logger name="*" minlevel="Info" writeTo="file"/> </rules> </nlog> 我想知道是否有任何方法可以用来检查NLog是否完成了日志消息,如下所示: for (int i = 0; i <= 9999; i++) { LogManager.GetCurrentClassLogger().Info("this is for testing " + i); } while(!LogManager.finished()) // check if finished or not { Console.Write("."); } Console.Write("done"); 谢谢. 看 解决方法
没有你可以检查的布尔值,但你可以调用flush – 当调用完成后,日志记录就完成了.
例如 for (int i = 0; i <= 9999; i++) { LogManager.GetCurrentClassLogger().Info("this is for testing " + i); } LogManager.Flush(); //flushes all async targets and block until done. There is also an optional timeout. Console.Write("done"); 见LogManager methods (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |