Last updated: 2006-09-18
This website is based on NLog v20060918.
Click here to view the documentation
for other versions.
| How to write your own TargetWhy would I want to write a Target?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 How to write a target?
It's really easy. Create a class that inherits from
If your target can optimize for batch writes you should also override the ExampleThis is a skeleton target that writes messages to the specified host. Compile using:
How to use the newly created target?It's easy. Just put the target in a DLL and reference it from the the config file using the <extensions /> clause as described here. Configuration file exampleHow to pass configuration options to the target?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 <target /> definition gets passed to the appropriate public property. NLog takes care of the appropriate conversions necessary so that you can use integer, string, datetime, boolean parameters. Do I really need to create a separate DLL?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 <extensions /> clause. Last updated: 2006-07-10 11:32:55 | |||||||
| Copyright © 2004-2006 by Jarosław Kowalski. |