Last updated: 2006-09-18

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

Log Targets

Targets represents possible log outputs. You can define one or more targets in the configuration file with the directive. When defining a target you need to specify its name and type.

The following types of targets are supported by NLog:

  • Regular Targets - which write the log messages to some output
  • Target Wrappers - which modify the behaviour of a target by adding features such as asynchronous processing, buffering, filtering and so on.
  • Compound Targets - which route the log messages to one or more attached targets - they can be used to provide failover, load balancing, log splitting and so on

Regular Targets

Regular targets are responsible for writing log output to persistent media, such as files, databases, network receivers or message queues. Each target has its own set of type-specific configuration parameters which are passed as XML attributes or elements.

The following example defines a single file target with a file name of 'file.txt':

<targets> 
    <target name="n" type="File" fileName="file.txt"/> 
</targets>  

The following log targets are available. Click on a target name for a reference of possible target parameters.

NameDescription.NET Framework.NET CFMono on WindowsMono on Unix
1.01.12.01.02.01.02.01.02.0
ASPNetTrace Writes logging messages to the ASP.NET trace.   
ASPResponse Outputs logging messages through the ASP Response object.       
Chainsaw Sends logging messages to the remote instance of Chainsaw application from log4j.
ColoredConsole Writes logging messages to the console with customizable coloring.     
Console Writes logging messages to the console.
Database Writes logging messages to the database using an ADO.NET provider.
Debug Counts logging messages but does not output them anywhere. Provides the counter of logged messages and remembers the latest one.
Debugger Writes logging messages to the attached managed debugger (for example Visual Studio .NET or DbgCLR).   
EventLog Writes log message to the Event Log.       
File Writes logging messages to one or more files.
FormControl Log text to Windows.Forms.Control.Text property control of specified Name       
Mail Sends logging messages by email using SMTP protocol.   
Memory Writes logging messages to an ArrayList in memory for programmatic retrieval.
MessageBox Pops up logging messages as message boxes.
MethodCall Calls the specified static method on each logging message and passes contextual parameters to it.
MSMQ Writes log message to the specified message queue handled by MSMQ.     
Network Sends logging messages over the network.
NLogViewer Sends logging messages to the remote instance of NLog Viewer.
Null Discards logging messages optionally forcing the layouts to be calculated. Used mainly for debugging and benchmarking.
OutputDebugString Outputs logging messages through the OutputDebugString() Win32 API.     
PerfCounter Increments specified performance counter on each write.       
RichTextBox Log text to Text property of RichTextBox of specified Name       
Trace Sends logging messages through System.Diagnostics.Trace   
WebService Calls the specified web service on each logging message.

Target Wrappers

Target wrappers are used to modify the behavior of other targets by adding features such as:

  • asynchronous processing (wrapped target runs in a separate thread)
  • retry-on-error
  • buffering

The following target wrappers are available. Click on a target name for full reference.

NameDescription.NET Framework.NET CFMono on WindowsMono on Unix
1.01.12.01.02.01.02.01.02.0
ASPNetBufferingWrapper A target that buffers log events for the duration of the ASP.NET Request and sends them down to the wrapped target as soon as the request ends.   
AsyncWrapper A target wrapper that provides asynchronous, buffered execution of target writes.   
AutoFlushWrapper A target wrapper that causes a flush after each write on a wrapped target.
BufferingWrapper A target that buffers log events and sends them in batches to the wrapped target.
FilteringWrapper A target wrapper that filters log entries based on a condition.
ImpersonatingWrapper A target wrapper that impersonates another user for the duration of the write.     
PostFilteringWrapper A target wrapper that filters buffered log entries based on a set of conditions that are evaluated on all events.
RepeatingWrapper A target wrapper that repeats each log event the specified number of times.
RetryingWrapper A target wrapper that causes retries on wrapped target errors.

Compound Targets

The following compound targets are available. Click on the target name for full reference.

NameDescription.NET Framework.NET CFMono on WindowsMono on Unix
1.01.12.01.02.01.02.01.02.0
FallbackGroup A compound target that provides fallback-on-error functionality.
RandomizeGroup A compound target writes to a randomly-chosen target among the sub-targets.
RoundRobinGroup A compound target that forwards writes to the sub-targets in a round-robin fashion.
SplitGroup A compound target that writes logging events to all attached sub-targets.
Webwww.nlog-project.org