Consider NLog is already configured and logging messages to a file, I want to add a listener that will be called each time a message is logged. I read the documentation on NLog but what it says in document doesn't work. Does anyone know how to add a listener using Code in NLog. Thanks
A:
Have you tried to use MessageCall target ?
The documentation is here:
http://nlog-project.org/wiki/MethodCall_target#Logging_to_a_static_method
Jarek Kowalski
2010-06-14 02:18:41
A:
Maybe the answer to this question will help.
I will repeat the suggested code here:
LoggingConfiguration config = LogManager.Configuration;
var logFile = new FileTarget();
config.AddTarget("file", logFile);
logFile.FileName = fileName + ".log";
logFile.Layout = "${date} | ${message}";
var rule = new LoggingRule("*", LogLevel.Info, logFile);
config.LoggingRules.Add(rule);
LogManager.Configuration = config;
logger.Info("File converted!");
I haven't tried it, but if it works for you, you should consider voting up the answer in the linked thread. Note that it is ok if you want to vote my answer up as well.
wageoghe
2010-10-11 17:24:12