Last updated: 2006-09-18

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

RoundRobinGroup Target


A compound target that forwards writes to the sub-targets in a round-robin fashion.

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

Parameters (blue fields are required):

NameTypeDescription
namestring
The name of the target.

Example:

This example causes the messages to be written to either file1.txt or file2.txt. Each odd message is written to file2.txt, each even message goes to file1.txt.

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="file" xsi:type="RoundRobinGroup"> 
      <target xsi:type="File" fileName="${basedir}/file1.txt"/> 
      <target xsi:type="File" fileName="${basedir}/file2.txt"/> 
    </target> 
  </targets> 
  <rules> 
    <logger name="*" minlevel="Debug" writeTo="file"/> 
  </rules> 
</nlog> 

The above examples assume just one target and a single rule. See below for a programmatic configuration that's equivalent to the above config file:

using System; 
 
using NLog; 
using NLog.Targets; 
using NLog.Targets.Compound; 
using System.Diagnostics; 
 
class Example 
{ 
    static void Main(string[] args) 
    { 
        FileTarget file1 = new FileTarget(); 
        file1.FileName = "${basedir}/file1.txt"; 
 
        FileTarget file2 = new FileTarget(); 
        file2.FileName = "${basedir}/file2.txt"; 
 
        RoundRobinTarget target = new RoundRobinTarget(); 
        target.Targets.Add(file1); 
        target.Targets.Add(file2); 
 
        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