I am using NLog and I want to log into RichTextBox and file at the same time. And I want to configure the log-in program, not from the xml config file.
The following code only logs the last goal (file in this case). Can anyone help?
Rich Textbox AreaT1 = New Rich Textbox Target (); T1.Layout = "$ {date} $ {message}"; T1.ControlName = "rtb_log"; T1.FormName = "MainForm"; NLog.Config.SimpleConfigurator.ConfigureForTargetLogging (T1, LogLevel.Debug); File target t2 = new file target (); T2.Layout = "$ {date} $ {level} $ {message}"; T2.FileName = "$ {baseir} / logs / toggle.log"; T2.KeepFile Open = Wrong; T2.Encoding = "iso-8859-2"; NLog.Config.SimpleConfigurator.ConfigureForTargetLogging (T2, LogLivel.TACS); Logger Logger = LogManager.Get Loger ("Myloger");
Ok I should read the help file before posting a question I got But anyway, the answer is to use SplitTarget as follows ...
RichTextBoxTarget t1 = New RichTextBoxTarget (); T1.Layout = "$ {date} $ {message}"; T1.ControlName = "rtb_log"; T1.FormName = "MainForm"; File target t2 = new file target (); T2.Layout = "$ {date} $ {level} $ {message}"; T2.FileName = "$ {baseir} / logs / toggle.log"; T2.KeepFile Open = Wrong; T2.Encoding = "iso-8859-2"; Split target goal = new split target (); Target.Targets.Add (T1); Target.Targets.Add (T2); NLog.Config.SimpleConfigurator.ConfigureForTargetLogging (Target, LogLevel.Debug); Logger Logger = LogManager.Get Loger ("Myloger");
Comments
Post a Comment