CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 25
RichTextBoxTarget
Log text a Rich Text Box control in an existing or new form.
Platforms Supported: .NetFramework + .NetCore3.1 + NET6.0 + NET8.0 - Requires nuget-package NLog.Windows.Forms
<targets>
<target xsi:type="RichTextBox"
name="String"
layout="Layout"
height="Integer"
autoScroll="Boolean"
maxLines="Integer"
showMinimized="Boolean"
toolWindow="Boolean"
controlName="String"
formName="String"
width="Integer"
useDefaultRowColoringRules="Boolean"
allowAccessoryFormCreation="Boolean"
messageRetention="Enum"
supportLinks="Boolean"
>
<!-- repeated word-colorings -->
<word-coloring backgroundColor="String"
fontColor="String" ignoreCase="Boolean"
regex="String"
style="Enum"
text="String"
wholeWords="Boolean"/>
<!-- repeated row-colorings-->
<row-coloring backgroundColor="String"
condition="Condition"
fontColor="String"
style="Enum"/>
</target>
</targets>
Read more about using the Configuration File.
name - Name of the target.
layout - Layout used to format log messages. Required. Default: ${longdate}|${level:uppercase=true}|${logger}|${message}
supportLinks - Indicates whether results of ${rtb-link}
layout renderer would work as links (introduced in NLog.Windows.Forms 4.2). Default: false
.
Set to true
and use ${rtb-link}
layout renderer to add links to log messages in the attached control. Setup link click handler via RichTextBoxTarget.LinkClicked
event. Use RichTextBoxTarget.GetTargetByControl(RichTextBox control)
static method to access a target attached to a specific RichTextBox control.
Note that setting supportLinks
to true
would set target control's DetectUrls
property to false
. Not Supported in .NET Core 3.1. Supported in .NET Framework and .NET 5
height - Initial height of the form with rich text box.
This parameter is ignored when logging to existing form control.
autoScroll - Indicates whether scroll bar will be moved automatically to show most recent log entries.
maxLines - Maximum number of lines the rich text box will store (or 0 to disable this feature).
After exceeding the maximum number, first line will be deleted.
showMinimized - Indicates whether the created form will be initially minimized.
This parameter is ignored when logging to existing form control.
toolWindow - Indicates whether the created window will be a tool window. Default: true
This parameter is ignored when logging to existing form control. Tool windows have thin border, and do not show up in the task bar.
controlName - Name of RichTextBox to which Nlog will write.
formName - Name of the Form on which the control is located. If there is no open form of a specified name then NLog will create a new one.
width - Initial width of the form with rich text box.
This parameter is ignored when logging to existing form control.
allowAccessoryFormCreation - Indicates whether to create a new window if existing form control is not found (introduced in NLog.Windows.Forms 4.1). Default: true
- If set to
true
and no control matching specifiedformName
andcontrolName
combination is found during target initialization then a new window with a RichTextBox is created. Window parameters are governed bywidth
,height
,toolWindow
andshowMinimized
options. If matching control is found duringRichTextBoxTarget.ReInitializeAllTextboxes(form)
call, created window is destroyed and logging continues into newly found control. - If set to
false
no log messages are shown unless the matching control is found during target initialization orRichTextBoxTarget.ReInitializeAllTextboxes(form)
call.
messageRetention - Determines what happens with the log messages that were issued when no target is attached or when switching to another control (introduced in NLog.Windows.Forms 4.1). Default: None
. Possible values:
- None - Just skip logging events when no target control attached. Only new messages would be sent to rich text box after attachment. No additional resources are spent on this.
-
OnlyMissed - Store logging events only during periods when no target control attached. Only these messages would be sent to new rich text box after attachment. Messages that were sent to previous textbox are not stored and would not be shown. Number of events stored is limited by
maxLines
option. -
All - Store all events in an internal queue. After attaching to a new control all the stored messages would be repeated in it, including messages that were sent to previous textbox. Number of events stored is limited by
maxLines
option.
Note that all values except None
require maxLines
option to be set to a non-zero value.
wordColoringRules - The word highlighting rules. Collection
Each collection item is represented by <word-coloring /> element with the following attributes:
- backgroundColor - Background color. Names are identical with KnownColor enum extended with Empty value which means that background color won't be changed. Default: Empty
- fontColor - Font color. Names are identical with KnownColor enum extended with Empty value which means that font color won't be changed. Default: Empty
- ignoreCase - Indicates whether to ignore case when comparing texts. Boolean Default: False
- regex - Regular expression to be matched. You must specify either text or regex.
-
style - Font style of matched text. Possible values are the same as in FontStyle enum in System.Drawing.
Possible values:
- Bold -
- Italic -
- Regular -
- Strikeout -
- Underline -
text - Text to be matched. You must specify either text or regex.
wholeWords - Indicates whether to match whole words only. Boolean Default: False
useDefaultRowColoringRules - Indicates whether to use default coloring rules. Boolean Default: False
Default Rules:
- Trace: DarkGray & italic text
- Debug: Gray text
- Info: Black text
- Warn: Orange and underlined text
- Error: Red text, bold & italic
- Fatal: White & bold text with red background
rowColoringRules - The row coloring rules. Collection
Each collection item is represented by <row-coloring /> element with the following attributes:
- backgroundColor - Background color. Names are identical with KnownColor enum extended with Empty value which means that background color won't be changed. Default: Empty
- fontColor - Font color. Names are identical with KnownColor enum extended with Empty value which means that font color won't be changed. Default: Empty
- ignoreCase - Indicates whether to ignore case when comparing texts. Boolean Default: False
- regex - Regular expression to be matched. You must specify either text or regex.
-
style - Font style of matched text. Possible values are the same as in FontStyle enum in System.Drawing.
Possible values:- Bold -
- Italic -
- Regular -
- Strikeout -
- Underline - Possible values are the same as in FontStyle enum in System.Drawing