如何从 MemoryTarget NLog 异步读取日志项

How to read Log items from MemoryTarget NLog asynchronously

我用这个例子http://nlog-project.org/documentation/v2.0.1/html/T_NLog_Targets_MemoryTarget.htm

我想知道如何从 MemoryTarget NLog 异步读取 Log 项[=25] =] 填充 RichTextBox 例如?

using System;

 using NLog;
 using NLog.Targets;

 class Example
 {
     static void Main(string[] args)
     {
        MemoryTarget target = new MemoryTarget();
        target.Layout = "${message}";

        NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug);

        Logger logger = LogManager.GetLogger("Example");
        logger.Debug("log message");

        foreach (string s in target.Logs)
        {
            Console.Write("logged: {0}", s);
        }

        // Access to target.Logs async.
        // Have I target.Logs.Clear() the Logs when I get all items?
    }
}

有线索吗?

您需要创建一个新线程并将 MemoryTarget 传递给新的 trhead。

PS:写到RichTextBox已经在NLog.Windows.Forms package. See the official documentation中实现了如何使用。