Reputation: 37632
I use this example http://nlog-project.org/documentation/v2.0.1/html/T_NLog_Targets_MemoryTarget.htm
and I would like how we can read Log
items from MemoryTarget
NLog asynchronously to populate RichTextBox
for instance?
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?
}
}
Any clue?
Upvotes: 0
Views: 449
Reputation: 36790
You need to create a new thread and pass the MemoryTarget
to the new trhead.
PS: writing to the RichTextBox
is already implemented in the NLog.Windows.Forms package. See the official documentation how to use.
Upvotes: 1