Skip to content
Rolf Kristensen edited this page Sep 12, 2024 · 39 revisions

Sends log messages over the network using Tcp / Udp / Tls / Http / Https

Platforms Supported: All

For SOAP-based webservice support over HTTP and HTTPS use WebService target.

Configuration Syntax

<targets>
  <target xsi:type="Network"
          name="String"
          onOverflow="Enum"
          newLine="Boolean"
          lineEnding="CRLF|LF|CR|Null|None"
          layout="Layout"
          maxMessageSize="Integer"
          encoding="Encoding"
          connectionCacheSize="Integer"
          maxConnections="Integer"
          maxQueueSize="Integer"
          keepConnection="Boolean"
          onConnectionOverflow="Enum"
          address="Layout"
          keepAliveTimeSeconds="Integer"
          sslProtocols="Enum" 
/>
</targets>

Read more about using the Configuration File.

Parameters

General Options

  • name - Name of the target.

Layout Options

  • layout - Layout used to format log messages. Layout Required. Default: ${longdate}|${level:uppercase=true}|${logger}|${message:withexception=true}

  • encoding - Encoding to be used. Encoding Default: utf-8

  • newLine - Indicates whether to append newline at the end of log message. Boolean Default: False

  • lineEnding - Line Ending to be used if newLine is set to true. LineEndingMode Default: CRLF. Not used if newLine is false. Introduced in 4.3.8. Possible values:

    • CRLF - Carriage Return and Line Feed (ASCII 13, ASCII 10). (default)
    • CR - Carriage Return (ASCII 13).
    • LF - Line Feed (ASCII 10).
    • NULL - Null terminator (ASCII 0)
    • None - No end of line characters.
  • compress - Use compression to reduce message size. Default: None

    Introduced with NLog 5.0

    • None - No compression (Default)
    • GZip - GZip with optimal compression
    • GZipFast - GZip with fastest compression
  • compressMinBytes - Use compression only when message size is higher than limit to reduce overhead in cpu-usage and additional headers. Default: 0

    Introduced with NLog 5.0

  • maxMessageSize - Maximum message size in bytes. Integer Default: 65000

    Notice when using UDP and the message-size exceeds MTU-size (default 1500 bytes), then IP fragmentation will happen. If network-switch/router has DontFragment enabled, then it will drop large network packets. Usually UDP is only used on local network since no authentication or security, and the network-switch seldom has DontFragment enabled (or under your control to be configured).

  • onOverflow - Action that should be taken if the message-size is larger than maxMessageSize. Possible values:

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

Connection Options

  • address - Network address. Layout
    The network address can be:

    • tcp://host:port - TCP (auto select IPv4/IPv6)
    • tcp4://host:port - force TCP/IPv4
    • tcp6://host:port - force TCP/IPv6
    • udp://host:port - UDP (auto select IPv4/IPv6)
    • udp4://host:port - force UDP/IPv4
    • udp6://host:port - force UDP/IPv6
    • http://host:port/pageName - HTTP using POST verb
    • https://host:port/pageName - HTTPS using POST verb
  • connectionCacheSize - Size of the connection cache (number of connections which are kept alive). Integer Default: 5

  • keepConnection - Indicates whether to keep connection open whenever possible. Not used for stateless protocols (= http, https) Boolean Default: True

  • maxConnections - Maximum current connections when keepConnection = false. 0 = no limit. Integer Default: 100 (Before NLog 5.0 the default was 0)

    Introduced in NLog 4.2.1

  • onConnectionOverflow - Action that should be taken when open connections are higher than limit maxConnections.

    Introduced in NLog 4.2.1.

    Possible enum values:

    • Discard - Discard new messages when reaching limit (Default) (Before NLog 5.0 it was enum value DiscardMessage)
    • Grow - Send message and ignore limit (Before NLog 5.0 it was enum value AllowNewConnnection)
    • Block - Block until pending connections has beeen freed.
  • maxQueueSize - Maximum queue size for a single connection. 0 means no limit. Integer. Default: 10000 (Before NLog 5.0 the default was 0)

    NLog 4.6.7 enabled queue-support for http/https and NLog 4.7.1 activated this setting for http/https. NLog 5.0.0 enabled queue-support for UDP.

  • onQueueOverflow - Action that should be taken if pending queue of messages is larger than maxQueueSize.

    Introduced with NLog 5.0

    • Discard - Discard the entire message (Default)
    • Grow - Ignore limit and grow the queue.
    • Block - Block until queue is below limit.
  • KeepAliveTimeSeconds - Idle time before first TCP keep-alive probe is sent. Faster detection of stale TCP connections. Currently only implemented for TCP. Integer. Default: 0 (Disabled)

    Introduced in NLog 4.6

  • SendTimeoutSeconds - Waiting time before TCP socket send-operation fails with timeout error. Default wait forever when network cable unplugged and tcp-buffer becomes full. Integer. Default: 0 (Disabled)

    Introduced in NLog 5.3.4

  • sslProtocols - Get or set the SSL/TLS protocols. Default no SSL/TLS is used. Currently only implemented for TCP. Invalid certificates are not supported.

    Introduced in NLog 4.6

    Possible values (combination allowed, comma separated):

    • None - No SSL/TLS is used
    • Default - Accepts Tls or Ssl3
    • Ssl2 - really not recommended
    • Ssl3 - not recommended
    • Tls - TLS 1.0
    • Tls11 - TLS 1.1
    • Tls12 - TLS 1.2
Clone this wiki locally