|
using System;
using NLog;
using NLog.Targets;
using NLog.Targets.Wrappers;
using System.Diagnostics;
class Example
{
static void Main(string[] args)
{
FileTarget wrappedTarget = new FileTarget();
wrappedTarget.FileName = "${basedir}/file.txt";
PostFilteringTargetWrapper postFilteringTarget = new PostFilteringTargetWrapper();
postFilteringTarget.WrappedTarget = wrappedTarget;
// set up default filter
postFilteringTarget.DefaultFilter = "level >= LogLevel.Info";
FilteringRule rule;
// if there are any warnings in the buffer
// dump the messages whose level is Debug or higher
rule = new FilteringRule();
rule.Exists = "level >= LogLevel.Warn";
rule.Filter = "level >= LogLevel.Debug";
postFilteringTarget.Rules.Add(rule);
BufferingTargetWrapper target = new BufferingTargetWrapper();
target.BufferSize = 100;
target.WrappedTarget = postFilteringTarget;
NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug);
Logger logger = LogManager.GetLogger("Example");
logger.Debug("log message");
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.