Debug Target Counts logging messages but does not output them anywhere. Provides the counter of logged messages and remembers the latest one. | Assembly | Class | .NET Framework | .NET CF | Mono on Windows | Mono on Unix |
|---|
| 1.0 | 1.1 | 2.0 | 1.0 | 2.0 | 1.0 | 2.0 | 1.0 | 2.0 |
|---|
| NLog.dll | NLog.Targets.DebugTarget |  |  |  |  |  |  |  |  |  |
Parameters (blue fields are required):| Name | Type | Description |
|---|
| layout | string
${} | | The text to be rendered. Default value is: ${longdate}|${level:uppercase=true}|${logger}|${message}. |
| | name | string | |
Example: To set up the target in the configuration file, use the following syntax: <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="debug" xsi:type="Debug" layout="${message}"/>
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="debug"/>
</rules>
</nlog>
This assumes just one target and a single rule. More configuration options are described here. To set up the log target programmatically use code like this: using System;
using NLog;
using NLog.Targets;
class Example
{
static void Main(string[] args)
{
DebugTarget target = new DebugTarget();
target.Layout = "${message}";
NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug);
Logger logger = LogManager.GetLogger("Example");
logger.Debug("log message");
logger.Debug("another log message");
Console.WriteLine("The debug target has been hit {0} times.", target.Counter);
Console.WriteLine("The last message was '{0}'.", target.LastMessage);
}
}
Back to the target list. |