Skip to content
Julian Verdurmen edited this page Sep 2, 2015 · 31 revisions

Log text a Rich Text Box control in an existing or new form.

Supported in .NET ##Configuration Syntax

<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">

<!-- 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. ##Parameters ###General Options name - Name of the target. ###Layout Options layout - Layout used to format log messages. Required. Default: ${longdate}|${level:uppercase=true}|${logger}|${message} ###Form Options 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.

###Highlighting Options 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 cooring rules.Boolean Default: False

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

Clone this wiki locally