[This is preliminary documentation and is subject to change.]

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

Namespace:  NLog.Targets
Assembly:  NLog (in NLog.dll) Version: 2.0.1.0

Syntax

C#
public sealed class FormControlTarget : TargetWithLayout
Visual Basic (Declaration)
Public NotInheritable Class FormControlTarget _
	Inherits TargetWithLayout
Visual Basic (Usage)
Dim instance As FormControlTarget

Examples

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

CopyXML
 1<?xml version="1.0" encoding="utf-8" ?>
 2<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
 3      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 4
 5    <targets>
 6        <target name="control" xsi:type="FormControl" append="true" controlName="textBox1" formName="Form1" />
 7    </targets>
 8
 9    <rules>
10        <logger name="*" minlevel="Debug" writeTo="control" />
11    </rules>
12</nlog>

The result is:

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

CopyC#
 1using System;
 2using System.Text;
 3using System.Windows.Forms;
 4using NLog;
 5using NLog.Targets;
 6
 7namespace RichTextBox2
 8{
 9    public partial class Form1 : Form
10    {
11        public Form1()
12        {
13            InitializeComponent();
14        }
15
16        private void Form1_Load(object sender, EventArgs e)
17        {
18
19            FormControlTarget target = new FormControlTarget();
20            target.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}";
21            target.ControlName = "textBox1";
22            target.FormName = "Form1";
23            target.Append = true;
24
25            NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Trace);
26
27            Logger logger = LogManager.GetLogger("Example");
28            logger.Trace("trace log message, ");
29            logger.Debug("debug log message, ");
30            logger.Info("info log message, ");
31            logger.Warn("warn log message, ");
32            logger.Error("error log message, ");
33            logger.Fatal("fatal log message");
34        }
35    }
36}
,

Inheritance Hierarchy

Object
  NLog.Targets..::.Target
    NLog.Targets..::.TargetWithLayout
      NLog.Targets..::.FormControlTarget

See Also