Click or drag to resize

FormControlTarget Class

Logs text to Windows.Forms.Control.Text property control of specified Name.
Inheritance Hierarchy
SystemObject
  NLog.TargetsTarget
    NLog.TargetsTargetWithLayout
      NLog.Windows.FormsFormControlTarget

Namespace:  NLog.Windows.Forms
Assembly:  NLog.Windows.Forms (in NLog.Windows.Forms.dll) Version: 5.2.3+a6f5d4397ec11371a92ffd5b29f2da9844f01c95
Syntax
public sealed class FormControlTarget : TargetWithLayout

The FormControlTarget type exposes the following members.

Constructors
  NameDescription
Public methodFormControlTarget
Initializes a new instance of the FormControlTarget class.
Top
Properties
  NameDescription
Public propertyAppend
Gets or sets a value indicating whether log text should be appended to the text of the control instead of overwriting it.
Public propertyControlName
Gets or sets the name of control to which NLog will log write log text.
Public propertyFormName
Gets or sets the name of the Form on which the control is located.
Public propertyLayout
Gets or sets the layout used to format log messages.
(Inherited from TargetWithLayout.)
Public propertyName
Gets or sets the name of the target.
(Inherited from Target.)
Public propertyReverseOrder
Gets or sets whether new log entry are added to the start or the end of the control
Top
Methods
  NameDescription
Public methodDispose
Closes the target.
(Inherited from Target.)
Public methodFlush
Flush any pending log messages (in case of asynchronous targets).
(Inherited from Target.)
Public methodPrecalculateVolatileLayouts
Calls the Precalculate(LogEventInfo) on each volatile layout used by this target. This method won't prerender if all layouts in this target are thread-agnostic.
(Inherited from Target.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Target.)
Public methodWriteAsyncLogEvent
Writes the log to the target.
(Inherited from Target.)
Public methodWriteAsyncLogEvents(AsyncLogEventInfo)
Writes the array of log events.
(Inherited from Target.)
Public methodWriteAsyncLogEvents(IListAsyncLogEventInfo)
Writes the array of log events.
(Inherited from Target.)
Top
Examples

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

XML
 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:

C#
1!ERROR: See log file!
,
See Also