NLogViewer Target Sends logging messages to the remote instance of NLog Viewer. | 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.NLogViewerTarget |  |  |  |  |  |  |  |  |  |
Parameters (blue fields are required):| Name | Type | Description |
|---|
| name | string | | | address | string | | The network address. Can be tcp://host:port or udp://host:port |
| | appInfo | string | | The AppInfo field. By default it's the friendly name of the current AppDomain. |
| | encoding | string | | Encoding Default value is: utf-8. |
| | includeCallSite | boolean | | Include call site (class and method name) in the information sent over the network. |
| | includeMDC | boolean | | Include MDC dictionary in the information sent over the network. |
| | includeNDC | boolean | | | includeNLogData | boolean | | Include NLog-specific extensions to log4j schema. |
| | includeSourceInfo | boolean | | Include source info (file name and line number) in the information sent over the network. |
| | keepConnection | boolean | | Keep connection open whenever possible. Default value is: True. |
| | maxMessageSize | integer | | Maximum message size in bytes. Default value is: 65000. |
| | newLine | boolean | | Append newline at the end of log message. Default value is: False. |
| | onOverflow | OverflowAction | | 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/>
| | Name | Type | Description |
|---|
| name | string | | | layout | string
${} | | 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. |