[This is preliminary documentation and is subject to change.]

Sends log messages to the remote instance of NLog Viewer.

Namespace:  NLog.Targets
Assembly:  NLog (in NLog.dll) Version: 2.0.1.0

Syntax

C#
public class NLogViewerTarget : NetworkTarget
Visual Basic (Declaration)
Public Class NLogViewerTarget _
	Inherits NetworkTarget
Visual Basic (Usage)
Dim instance As NLogViewerTarget

Examples

To set up the target in the configuration file, use the following syntax:

CopyXML
 1<?xml version="1.0" ?>
 2<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
 3      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 4    <targets>
 5        <target name="viewer" xsi:type="NLogViewer" address="ucp://localhost:4000" />
 6    </targets>
 7
 8    <rules>
 9        <logger name="*" minlevel="Debug" writeTo="viewer" />
10    </rules>
11</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:

CopyC#
 1using NLog;
 2using NLog.Targets;
 3
 4class Example
 5{
 6    static void Main(string[] args)
 7    {
 8        NLogViewerTarget target = new NLogViewerTarget();
 9        target.Address = "udp://localhost:4000";
10
11        NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug);
12
13        Logger logger = LogManager.GetLogger("Example");
14        logger.Trace("log message 1");
15        logger.Debug("log message 2");
16        logger.Info("log message 3");
17        logger.Warn("log message 4");
18        logger.Error("log message 5");
19        logger.Fatal("log message 6");
20    }
21}

NOTE: If your receiver application is ever likely to be off-line, don't use TCP protocol or you'll get TCP timeouts and your application will crawl. Either switch to UDP transport or use AsyncWrapper target so that your application threads will not be blocked by the timing-out connection attempts.

Inheritance Hierarchy

Object
  NLog.Targets..::.Target
    NLog.Targets..::.TargetWithLayout
      NLog.Targets..::.NetworkTarget
        NLog.Targets..::.NLogViewerTarget
          NLog.Targets..::.ChainsawTarget

See Also