Debug target

Michael Freidgeim edited this page Dec 31, 2016 · 3 revisions
Clone this wiki locally

Mock target - useful for testing.

Supported in .NET, Silverlight, Compact Framework and Mono

Configuration Syntax

  <target xsi:type="Debug" name="String" layout="Layout" />

Read more about using the Configuration File.


General Options

name - Name of the target.

Layout Options

layout - Layout used to format log messages. Layout Required. Default: ${longdate}|${level:uppercase=true}|${logger}|${message}


Logging to Debug Target(snippet from Debug Simple Example.cs )

    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);

Some examples of DebugTarget use can be found in unit tests