If you want to write your trace messages to some non-standard output (for example to some management tool or over the network or using the PPPoP (PPP-over-pigeon protocol) you need to write a custom Target.
It's really easy. Create a class that inherits from NLog.TargetWithLayout (or
NLog.Target if you don't want to use layout) and override
the Write(LogEventInfo) method. In the body of the method use
CompiledLayout.GetFormattedMessage() to get the message text, then send the text to the destination media.
If your target can optimize for batch writes you should also override the Write(LogEventInfo[]) method.
This is a skeleton target that writes messages to the specified host. Compile using:
csc.exe /t:library /out:MyAssembly.dll /r:NLog.dll MyFirstTarget.cs
It's easy. Just put the target in a DLL and reference it from the the config file using the
Consider the above example. There's a property called "Host" that does just that.
Having a public property that sets the required configuration parameters is enough for NLog to use it.
Each attribute that you put in the
Not really. You can use TargetFactory.AddTarget() to register your target programmatically.
Just be sure to to it at the very beginning of your program before any log messages are written.
It should be possible to reference your EXE using the