Last updated: 2006-09-18

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

BufferingWrapper Target


A target that buffers log events and sends them in batches to the wrapped target.

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

Parameters (blue fields are required):

NameTypeDescription
namestring
The name of the target.
bufferSizeinteger
Number of log events to be buffered.

Default value is: 100.

flushTimeoutinteger
Flush the contents of buffer if there's no write in the specified period of time (milliseconds). Use -1 to disable timed flushes.

Default value is: -1.

wrappedTargetTarget
The target that this target wraps.

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="file" xsi:type="BufferingWrapper" bufferSize="100"> 
      <target xsi:type="File" fileName="${basedir}/file.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.Wrappers; 
using System.Diagnostics; 
 
class Example 
{ 
    static void Main(string[] args) 
    { 
        FileTarget wrappedTarget = new FileTarget(); 
        wrappedTarget.FileName = "${basedir}/file.txt"; 
 
        BufferingTargetWrapper target = new BufferingTargetWrapper(); 
        target.BufferSize = 100; 
        target.WrappedTarget = wrappedTarget; 
 
        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