Skip to content

A Serilog sink that writes log events to a WPF RichTextBox control with colors and theme support

License

Notifications You must be signed in to change notification settings

MediatedCommunications/serilog-sinks-richtextbox

This branch is 29 commits ahead of, 58 commits behind serilog-contrib/serilog-sinks-richtextbox:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

b17fd44 · Mar 11, 2025

History

70 Commits
Dec 6, 2021
Dec 16, 2021
Feb 23, 2021
Sep 26, 2021
Mar 11, 2025
Dec 20, 2021
Dec 8, 2021
Feb 13, 2021
Sep 26, 2021
Aug 21, 2021
Feb 13, 2021
Feb 23, 2021
Feb 13, 2021
Sep 26, 2021
Dec 6, 2021
Feb 23, 2021
Feb 23, 2021
Mar 17, 2021
Feb 23, 2021
Dec 20, 2021
Apr 7, 2021
Sep 26, 2021
Feb 23, 2021

Repository files navigation

README.md
Serilog.Sinks.RichTextBox.Wpf

Serilog.Sinks.RichTextBox.Wpf

A Serilog sink that writes log events to any WPF RichTextBox control with coloring and custom theme support.

NuGet Version .NET .NET Core .NET Framework Stack Overflow

Screenshot of Serilog.Sinks.RichTextBox.Wpf in action

Give a Star! ⭐

If you like or are using this project please give it a star. Thanks!

Getting started 🚀

Install the Serilog.Sinks.RichTextBox.Wpf package from NuGet:

Install-Package Serilog.Sinks.RichTextBox.Wpf -Prerelease

Declare your RichTextBox control and give it a name that you can reference it from the code-behind. e.g.:

<Window (...)>
  <RichTextBox
      x:Name="MyRichTextBox"
      Background="Black"
      Foreground="LightGray"
      FontFamily="Cascadia Mono, Consolas, Courier New, monospace"
      VerticalScrollBarVisibility="Auto"
  />
</Window>

Then enable the sink using WriteTo.RichTextBox():

Log.Logger = new LoggerConfiguration()
    .WriteTo.RichTextBox(MyRichTextBox)
    .CreateLogger();

Log.Information("Hello, world!");

Log events will be written to the RichTextBox control:

[11:54:36 INF] Hello, world!

Themes

The sink will colorize output by default:

Screenshot of Serilog.Sinks.RichTextBox.Wpf in action

Themes can be specified when configuring the sink:

    .WriteTo.RichTextBox(MyRichTextBox, theme: RichTextBoxConsoleTheme.Grayscale)

The following built-in themes are available at this time:

Theme Description
RichTextBoxTheme.None No styling. Uses default styles applied to the RichTextBox control
RichTextBoxConsoleTheme.Literate Styled to replicate the default theme of Serilog.Sinks.Console; This is the default when no theme is specified
RichTextBoxConsoleTheme.Grayscale A theme using only shades of gray, white, and black
RichTextBoxConsoleTheme.Colored A theme based on the original Serilog.Sinks.ColoredConsole sink

Adding a new theme is straightforward; examples can be found in the RichTextBoxConsoleThemes class.

Output templates

The format of events to the RichTextBox can be modified using the outputTemplate configuration parameter:

    .WriteTo.RichTextBox(MyRichTextBox,
        outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")

The default template, shown in the example above, uses built-in properties like Timestamp and Level. Properties from events, including those attached using enrichers, can also appear in the output template.

Release History

Click on the Releases tab on GitHub.


Copyright © 2021 C. Augusto Proiete & Contributors - Provided under the Apache License, Version 2.0.

About

A Serilog sink that writes log events to a WPF RichTextBox control with colors and theme support

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 99.6%
  • Other 0.4%