Click or drag to resize

RichTextBoxTarget Class

Log text a Rich Text Box control in an existing or new form.
Inheritance Hierarchy
SystemObject
  NLog.TargetsTarget
    NLog.TargetsTargetWithLayout
      NLog.Windows.FormsRichTextBoxTarget

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

The RichTextBoxTarget type exposes the following members.

Constructors
  NameDescription
Public methodRichTextBoxTarget
Initializes a new instance of the RichTextBoxTarget class.
Top
Properties
  NameDescription
Public propertyAllowAccessoryFormCreation
Gets or sets a value indicating whether to create accessory form if the specified form/control combination was not found during target initialization.
Public propertyAutoScroll
Gets or sets a value indicating whether scroll bar will be moved automatically to show most recent log entries.
Public propertyControlName
Gets or sets the Name of RichTextBox to which Nlog will write.
Public propertyCreatedForm
Form created (true) or used an existing (false). Set after InitializeTarget. Can be true only if AllowAccessoryFormCreation is set to true (default).
Public propertyStatic memberDefaultRowColoringRules
Gets the default set of row coloring rules which applies when UseDefaultRowColoringRules is set to true.
Public propertyFormName
Gets or sets the name of the Form on which the control is located. If there is no open form of a specified name than NLog will create a new one.
Public propertyHeight
Gets or sets the initial height of the form with rich text box.
Public propertyLayout
Gets or sets the layout used to format log messages.
(Inherited from TargetWithLayout.)
Public propertyMaxLines
Gets or sets the maximum number of lines the rich text box will store (or 0 to disable this feature).
Public propertyMessageRetention
gets or sets the message retention strategy which determines how the target handles messages when there's no control attached, or when switching between controls
Public propertyName
Gets or sets the name of the target.
(Inherited from Target.)
Public propertyRowColoringRules
Gets the row coloring rules.
Public propertyShowMinimized
Gets or sets a value indicating whether the created form will be initially minimized.
Public propertySupportLinks
If set to true, using "rtb-link" renderer (RichTextBoxLinkLayoutRenderer) would create clickable links in the control.
Public propertyTargetForm
Gets or sets the form to log to.
Public propertyTargetRichTextBox
Gets or sets the rich text box to log to.
Public propertyToolWindow
Gets or sets a value indicating whether the created window will be a tool window.
Public propertyUseDefaultRowColoringRules
Gets or sets a value indicating whether to use default coloring rules.
Public propertyWidth
Gets or sets the initial width of the form with rich text box.
Public propertyWordColoringRules
Gets the word highlighting rules.
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 methodStatic memberGetTargetByControl(RichTextBox)
Returns a target attached to a given RichTextBox control
Public methodStatic memberGetTargetByControl(RichTextBox, LoggingConfiguration)
Returns a target attached to a given RichTextBox control
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 methodStatic memberReInitializeAllTextboxes(Form)
Attempts to attach existing targets that have yet no textboxes to controls that exist on specified form if appropriate
Public methodStatic memberReInitializeAllTextboxes(Form, LoggingConfiguration)
Attempts to attach existing targets that have yet no textboxes to controls that exist on specified form if appropriate
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
Events
  NameDescription
Public eventLinkClicked
Event fired when the user clicks on a link in the control created by the "rtb-link" renderer (RichTextBoxLinkLayoutRenderer).
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="richTextBox" xsi:type="RichTextBox" controlName="richTextBox1" formName="form1" useDefaultRowColoringRules="false"/>
 7    </targets>
 8
 9    <rules>
10        <logger name="*" minlevel="Debug" writeTo="richTextBox" />
11    </rules>
12</nlog>

The result is:

To set up the target with coloring rules 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="richTextBox" xsi:type="RichTextBox" controlName="richTextBox1" formName="form1" useDefaultRowColoringRules="true">
 7            <row-coloring condition="contains(message,'serious')" fontColor="Red" backgroundColor="Blue" style="Underline,Italic" />
 8        </target>
 9    </targets>
10
11    <rules>
12        <logger name="*" minlevel="Debug" writeTo="richTextBox" />
13    </rules>
14</nlog>
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="richTextBox" xsi:type="RichTextBox" controlName="richTextBox1" formName="form1" useDefaultRowColoringRules="true">
 7            <word-coloring text="message" fontColor="Green" backgroundColor="Black"/>
 8        </target>
 9    </targets>
10
11    <rules>
12        <logger name="*" minlevel="Debug" writeTo="richTextBox" />
13    </rules>
14</nlog>

The result is:

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

C#
1!ERROR: See log file!
,
C#
1!ERROR: See log file!
for RowColoring,
C#
1!ERROR: See log file!
for WordColoring
See Also