Last updated: 2006-09-18

This website is based on NLog v1.0. Click here to view the documentation for other versions.

Null Target


Discards logging messages optionally forcing the layouts to be calculated. Used mainly for debugging and benchmarking.

AssemblyClass.NET Framework.NET CFMono on WindowsMono on Unix
1.01.12.01.02.01.02.01.02.0
NLog.dllNLog.Targets.NullTarget

Parameters (blue fields are required):

NameTypeDescription
layoutstring  ${}
The text to be rendered.

Default value is: ${longdate}|${level:uppercase=true}|${logger}|${message}.

namestring
The name of the target.
formatMessageboolean
Perform layout calculation.

Default value is: False.

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="n" xsi:type="Null" layout="${message}" formatMessage="true"/> 
  </targets> 
  <rules> 
    <logger name="*" minlevel="Debug" writeTo="n"/> 
  </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) 
    { 
        NullTarget target = new NullTarget(); 
        target.Layout = "${message}"; 
        target.FormatMessage = true; 
 
        NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug); 
 
        Logger logger = LogManager.GetLogger("Example"); 
        logger.Debug("log message"); 
    } 
}

Back to the target list.
Webwww.nlog-project.org