簡體   English   中英

如何檢查NLog是否已在異步模式下從隊列中記錄消息?

[英]how to check if the NLog has finished logging the messages from its queue in asynchronous mode?

我有一個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方法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM