RetryingWrapper Target A target wrapper that causes retries on wrapped target errors. | Assembly | Class | .NET Framework | .NET CF | Mono on Windows | Mono on Unix |
|---|
| 1.0 | 1.1 | 2.0 | 1.0 | 2.0 | 1.0 | 2.0 | 1.0 | 2.0 |
|---|
| NLog.dll | NLog.Targets.Wrappers.RetryingTargetWrapper |  |  |  |  |  |  |  |  |  |
Parameters (blue fields are required):| Name | Type | Description |
|---|
| name | string | | | retryCount | integer | | Number of retries that should be attempted on the wrapped target in case of a failure. Default value is: 3. |
| | retryDelayMilliseconds | integer | | The time to wait between retries in milliseconds. Default value is: 100. |
| | wrappedTarget | Target | | The target that this target wraps. |
|
Example:This example causes each write attempt to be repeated 3 times, sleeping 1 second between attempts if first one fails. 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="RetryingWrapper" retryCount="3"
retryDelayMilliseconds="1000">
<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";
RetryingTargetWrapper target = new RetryingTargetWrapper();
target.WrappedTarget = wrappedTarget;
target.RetryCount = 3;
target.RetryDelayMilliseconds = 1000;
NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug);
Logger logger = LogManager.GetLogger("Example");
logger.Debug("log message");
}
}
Back to the target list. |