-
Notifications
You must be signed in to change notification settings - Fork 1.4k
NLogViewer target
Sends log messages to the remote instance of Log4J XML Viewer.
Platforms Supported: All
This target inherits from the Network Target, and so it has also all the properties of the Network Target available. Using the Log4JXmlEventLayout to produce Log4J XML output.
<targets>
<target xsi:type="NLogViewer"
name="String"
layout="Layout"
newLine="Boolean"
onOverflow="Enum"
maxMessageSize="Integer"
encoding="Encoding"
connectionCacheSize="Integer"
address="Layout"
lineEnding="CRLF|LF|CR|None"
maxConnections="Integer"
maxQueueSize="Integer"
keepConnection="Boolean"
onConnectionOverflow="Enum"
includeSourceInfo="Boolean"
includeCallSite="Boolean"
appInfo="String"
ndcItemSeparator="String"
includeNdc="Boolean"
includeNLogData="Boolean">
<parameter layout="Layout" name="String"/><!-- repeated -->
</target>
</targets>
Read more about using the Configuration File.
- name - Name of the target.
-
layout - Instance of Log4JXmlEventLayout that is used to format log messages. Layout Default: Log4JXmlEventLayout
-
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 isfalse
. 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.
-
maxMessageSize - Maximum message size in bytes. Integer Default: 65000
-
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)
-
connectionCacheSize - Size of the connection cache (number of connections which are kept alive). Integer Default: 5
-
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 For SOAP-based webservice support over HTTP use WebService target.
-
keepConnection - Indicates whether to keep connection open whenever possible. Boolean Default: True
-
maxConnections - Maximum current connections. 0 = no maximum.
Integer
Default:16
. Not used if keepConnection istrue
.Introduced with NLog v4.2.1. Default became
16
with NLog v4.5 (Before0
) -
onConnectionOverflow - Action that should be taken if the will be more connections than maxConnections.
Introduced with NLog v4.2.1. Default became
Block
with NLog v4.5 (BeforeAllowNewConnnection
)Possible values:
- AllowNewConnnection - Just allow it.
- Block - Block until there's more room in the queue. (default)
- DiscardMessage - Discard the connection item.
-
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.
-
includeSourceInfo - Indicates whether to include source info (file name and line number) in the information sent over the network. Default:
false
. -
includeCallSite - Indicates whether to include call site (class and method name) in the information sent over the network. Default:
false
. -
includeNLogData - Indicates whether to include NLog-specific extensions to log4j schema. Default:
true
. -
IncludeEventProperties - Include all events properties of a logevent? Default:
false
.Before NLog 5.0 option was named IncludeAllProperties
-
IncludeScopeProperties - Indicates whether to include ScopeContext Properties dictionary. Default:
false
.Before NLog 5.0 option was named IncludeMdlc or IncludeMdc
-
IncludeScopeNested - Indicates whether to include ScopeContext Nested Stack as NDC. Default:
false
.Before NLog 5.0 option was named IncludeNdlc
-
ScopeNestedSeparator - NDC item separator. Default:
Before NLog 5.0 option was named NdlcItemSeparator
-
includeNdc - Indicates whether to include ScopeContext Nested Stack. Default:
false
. -
ndcItemSeparator - NDC item separator. Default:
-
appInfo - AppInfo field. By default it's the friendly name of the current AppDomain.
-
loggerName - Logger field. By default it's the output of
${logger}
Introduced in NLog 4.5
-
formattedMessage - Message field. By default it's the output of
${message}
Introduced in NLog 5.3
-
parameter - Additional context properties that should be included.
- name - Name of Parameter. Required.
- layout - The layout for the Parameter-Value. Required.
<?xml version="1.0" encoding="utf-8"?>
<nlog throwConfigExceptions="true">
<targets>
<target name="log4view" xsi:type="NLogViewer" address="udp://127.0.0.1:5001" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="log4view" />
</rules>
</nlog>
Available Log4J-XML viewers (See also LogViewer Tools)
- Sentinel - Avoid using TCP since not complete.
- Log2Console
- Logazmic
- Loginator
- Logbert
- LogViewer
- Lilith
- OtrosLogViewer
Notice that most Log4J-XML viewers will drop messages and stall when NLog sends messages at full speed. One can consider to throttle NLog like this:
<?xml version="1.0" encoding="utf-8"?>
<nlog throwConfigExceptions="true">
<targets>
<target name="throttle_log4view" type="AsyncWrapper" timeToSleepBetweenBatches="50" batchSize="1" overflowAction="Block">
<target name="log4view" type="NLogViewer" address="tcp://127.0.0.1:5001" newline="true" />
</target>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="throttle_log4view" />
</rules>
</nlog>
- Troubleshooting Guide - See available NLog Targets and Layouts: https://nlog-project.org/config
- Getting started
- How to use structured logging
- Troubleshooting
- FAQ
- Articles about NLog
-
All targets, layouts and layout renderers
Popular: - Using NLog with NLog.config
- Using NLog with appsettings.json