Last updated: 2006-09-18

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

NLogViewer Target


Sends logging messages to the remote instance of NLog Viewer.

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

Parameters (blue fields are required):

NameTypeDescription
namestring
The name of the target.
addressstring
The network address. Can be tcp://host:port or udp://host:port
appInfostring
The AppInfo field. By default it's the friendly name of the current AppDomain.
encodingstring
Encoding

Default value is: utf-8.

includeCallSiteboolean
Include call site (class and method name) in the information sent over the network.
includeMDCboolean
Include MDC dictionary in the information sent over the network.
includeNDCboolean
Include NDC stack.
includeNLogDataboolean
Include NLog-specific extensions to log4j schema.
includeSourceInfoboolean
Include source info (file name and line number) in the information sent over the network.
keepConnectionboolean
Keep connection open whenever possible.

Default value is: True.

maxMessageSizeinteger
Maximum message size in bytes.

Default value is: 65000.

newLineboolean
Append newline at the end of log message.

Default value is: False.

onOverflowOverflowAction
Action that should be taken if the message is larger than maxMessageSize

Possible values are:

  • Error - Report an error.
  • Split - Split the message into smaller pieces.
  • Discard - Discard the entire message

Parameters Collection of NLogViewerParameterInfo. Each element is represented as <parameter/>
NameTypeDescription
namestring
Viewer parameter name.
layoutstring  ${}
The layout that should be use to calcuate the value for the parameter.

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="viewer" xsi:type="NLogViewer" address="ucp://localhost:4000"/> 
  </targets> 
  <rules> 
    <logger name="*" minlevel="Debug" writeTo="viewer"/> 
  </rules> 
</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:

using NLog; 
using NLog.Targets; 
 
class Example 
{ 
    static void Main(string[] args) 
    { 
        NLogViewerTarget target = new NLogViewerTarget(); 
        target.Address = "udp://localhost:4000"; 
 
        NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug); 
 
        Logger logger = LogManager.GetLogger("Example"); 
        logger.Trace("log message 1"); 
        logger.Debug("log message 2"); 
        logger.Info("log message 3"); 
        logger.Warn("log message 4"); 
        logger.Error("log message 5"); 
        logger.Fatal("log message 6"); 
    } 
}

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.


Back to the target list.
Webwww.nlog-project.org