Last updated: 2006-09-18

This website is based on NLog v1.0. Click here to view the documentation for other versions.

FormControl Target


Log text to Windows.Forms.Control.Text property control of specified Name

AssemblyClass.NET Framework.NET CFMono on WindowsMono on Unix
1.01.12.01.02.01.02.01.02.0
NLog.dllNLog.Targets.FormControlTarget      

Parameters (blue fields are required):

NameTypeDescription
controlNamestring
Name of control to which Nlog will log
layoutstring  ${}
The text to be rendered.

Default value is: ${longdate}|${level:uppercase=true}|${logger}|${message}.

namestring
The name of the target.
appendboolean
Setting to tell to append or overwrite the Text property of control
formNamestring
Name of the Form on which the control is located.

Example:

To set up the target in the configuration file, use the following syntax:

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
  <targets> 
    <target name="control" xsi:type="FormControl" append="true" 
            controlName="textBox1" formName="Form1"/> 
  </targets> 
  <rules> 
    <logger name="*" minlevel="Debug" writeTo="control"/> 
  </rules> 
</nlog> 

The result is:

To set up the log target programmatically similar to above use code like this:

using System; 
using System.Text; 
using System.Windows.Forms; 
using NLog; 
using NLog.Targets; 
 
namespace RichTextBox2 
{ 
    public partial class Form1 : Form 
    { 
        public Form1() 
        { 
            InitializeComponent(); 
        } 
 
        private void Form1_Load(object sender, EventArgs e) 
        { 
 
            FormControlTarget target = new FormControlTarget(); 
            target.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}"; 
            target.ControlName = "textBox1"; 
            target.FormName = "Form1"; 
            target.Append = true; 
 
            NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Trace); 
 
            Logger logger = LogManager.GetLogger("Example"); 
            logger.Trace("trace log message, "); 
            logger.Debug("debug log message, "); 
            logger.Info("info log message, "); 
            logger.Warn("warn log message, "); 
            logger.Error("error log message, "); 
            logger.Fatal("fatal log message"); 
        } 
    } 
}
,

Back to the target list.
Webwww.nlog-project.org