How to add a listener in NLog using Code -


Consider that NLog is already configured and logging messages in a file, I add a listener I want to be told a message every time a log is read, I read the documentation on analog, but what works in the document does not work. Does anyone know how to add a listener to code using NOLG Thanks

That will help

I will repeat the suggested code here:

logging configuration config = log manager. Configuration; Var logfile = new file target (); Config.AddTarget ("file", logfile); LogFile.FileName = fileName + ".log"; LogFile.Layout = "$ {date} | $ {message}"; Var rule = new logging rule ("*", LogLevel.Info, logfile); Config.loggingRules.Add (rules); LogManager.configuration = config; Logger.Info ("Change File!");

I have not tried to do this, but if it works for you, then you should consider answering the linked thread. Note that if you want to vote your answer then it is okay.


Comments