Custom NLog Appender

I am trying to write my own user to register with NLog. I saw some examples for log4net where I should write an appender that inherits from the abstract class AppenderSkeleton. Can anyone name an analog class in NLog?

+8
c # log4net nlog appender
source share
1 answer

The analogue of NLog analogue of log4net-applications will be the target. To create your own goal, you must inherit from NLog.Targets.TargetWithLayout . You should also mark your target class with the TargetAttribute attribute:

 [Target("Foo")] public class FooTarget : TargetWithLayout { protected override void Write(LogEventInfo logEvent) { Console.WriteLine(logEvent.Message); } } 

The next step is the assembly in which your class is defined for NLog extensions:

 <nlog> <extensions> <add assembly="MyBarAssembly"/> </extensions> <targets> ... 

And the last step is to register your target (NLog will look in the extensions for the TargetAttribute type TargetAttribute )

 <target name="foo" type="Foo"/> 
+9
source share

All Articles