-
Notifications
You must be signed in to change notification settings - Fork 1.4k
LogReceiverService target
Sends log messages to a NLog Receiver Service (using WCF or Web Services).
Platforms Supported: All - Requires nuget-package NLog.Wcf with NLog 5.0
<targets>
<target xsi:type="LogReceiverService"
name="String"
endpointConfigurationName="String"
endpointAddress="String"
useBinaryEncoding="Boolean"
clientId="Layout"
includeEventProperties="Boolean">
<parameter layout="Layout" name="String" type="System.Type"/><!-- repeated -->
</target>
</targets>
Read more about using the Configuration File.
- name - Name of the target.
-
endpointAddress - Endpoint address. Required.
-
endpointConfigurationName - Name of the endpoint configuration in WCF configuration file
Only supported on .NET Framework platform with
app.config
. Trying to enable on .NET Core fails with: System.PlatformNotSupportedException: Configuration files are not supported.
-
useBinaryEncoding - Indicates whether to use binary message encoding. Boolean
-
parameters - The list of parameters. Collection
Each collection item is represented by <parameter /> element with the following attributes:- layout - Layout that should be use to calculate the value for the parameter. Layout Required.
- name - Name of the parameter.
- type - Type of the parameter.System.Type
-
clientId - Application Client Identifier, translates into
NLogEvents.ClientName
Layout -
includeEventProperties - Indicates whether to include per-event properties in the payload sent to the server. Boolean
Parameters are passed to the WCF LogReceiverService target using one or more configuration lines such as:
<parameter name="MyParameter" layout="My Value!" />
<parameter name="nlogdir" layout="${nlogdir}" />
These parameters are passed over the network to the service and can be accessed by emitting events from your receiver application.
namespace MyLogReceiverApp
{
using System;
using NLog;
using NLog.LogReceiverService;
/// <summary>
/// Log service server object that logs messages.
/// </summary>
public class LogReceiverServer : ILogReceiverServer
{
public void ProcessLogMessages(NLogEvents nevents)
{
var events = nevents.ToEventInfo("Client.");
Console.WriteLine("in: {0} {1}", nevents.Events.Length, events.Count);
foreach (var ev in events)
{
var logger = LogManager.GetLogger(ev.LoggerName);
logger.Log(ev);
}
}
}
}
- 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