https://github.com/vonhoff/Serilog.Sinks.RichTextBox.WinForms.Colored
A Serilog sink that writes log events to a WinForms RichTextBox control with colors and theme support
https://github.com/vonhoff/Serilog.Sinks.RichTextBox.WinForms.Colored
colored colored-log colored-logging console forms high-contrast logger logging rich-text richtextbox serilog serilog-sink sink sinks themes windows-forms winforms
Last synced: 11 months ago
JSON representation
A Serilog sink that writes log events to a WinForms RichTextBox control with colors and theme support
- Host: GitHub
- URL: https://github.com/vonhoff/Serilog.Sinks.RichTextBox.WinForms.Colored
- Owner: vonhoff
- License: apache-2.0
- Created: 2022-05-09T12:44:52.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2025-07-13T07:47:24.000Z (11 months ago)
- Last Synced: 2025-07-19T05:41:39.219Z (11 months ago)
- Topics: colored, colored-log, colored-logging, console, forms, high-contrast, logger, logging, rich-text, richtextbox, serilog, serilog-sink, sink, sinks, themes, windows-forms, winforms
- Language: C#
- Homepage: https://www.nuget.org/packages/Serilog.Sinks.RichTextBox.WinForms.Colored
- Size: 502 KB
- Stars: 24
- Watchers: 2
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Serilog.Sinks.RichTextBox.WinForms.Colored
[](https://www.nuget.org/packages/Serilog.Sinks.RichTextBox.WinForms.Colored)
[](https://github.com/vonhoff/Serilog.Sinks.RichTextBox.WinForms.Colored/actions)
[](https://www.nuget.org/packages/Serilog.Sinks.RichTextBox.WinForms.Colored)
[](https://opensource.org/licenses/Apache-2.0)
A [Serilog](https://github.com/serilog/serilog) sink that writes log events to a [WinForms RichTextBox](https://docs.microsoft.com/en-us/dotnet/desktop/winforms/controls/richtextbox-control-overview-windows-forms) with support for coloring and custom themes.

## Features
- Colored log events in a WinForms RichTextBox control
- Multiple theme presets with customization options
- High-performance asynchronous processing
- Line limit to control memory usage
- WCAG compliant color schemes based on the [Serilog WPF RichTextBox](https://github.com/serilog-contrib/serilog-sinks-richtextbox) sink.
## Get Started
Install the package from NuGet:
```powershell
Install-Package Serilog.Sinks.RichTextBox.WinForms.Colored
```
Declare your RichTextBox control:
```csharp
private System.Windows.Forms.RichTextBox richTextBox1;
private void InitializeComponent()
{
this.richTextBox1.BackColor = System.Drawing.SystemColors.Window;
this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.richTextBox1.Font = new System.Drawing.Font("Cascadia Mono", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.richTextBox1.Location = new System.Drawing.Point(0, 0);
this.richTextBox1.Name = "richTextBox1";
}
```
Configure the logger to use the sink using the `RichTextBox` extension method:
```csharp
Log.Logger = new LoggerConfiguration()
.WriteTo.RichTextBox(richTextBox1, theme: ThemePresets.Literate)
.CreateLogger();
Log.Information("Hello, world!");
```
See the [Extension Method](Serilog.Sinks.RichTextBox.WinForms.Colored/RichTextBoxSinkLoggerConfigurationExtensions.cs) for more configuration options.
## Themes
Available built-in themes:
| Theme | Description |
|-----------------------------|------------------------------------------------------------------------------|
| `ThemePresets.Literate` | Styled to replicate the default theme of Serilog.Sinks.Console __(default)__ |
| `ThemePresets.Grayscale` | A theme using only shades of gray, white, and black |
| `ThemePresets.Colored` | A theme based on the original Serilog.Sinks.ColoredConsole sink |
| `ThemePresets.Luminous` | A light theme with high contrast for accessibility |
The themes based on the original sinks are slightly adjusted to be [WCAG compliant](https://www.w3.org/WAI/WCAG22/Understanding/contrast-minimum), ensuring that the contrast ratio between text and background colors is at least 4.5:1.
You can create your own custom themes by creating a new instance of the [Theme](Serilog.Sinks.RichTextBox.WinForms.Colored/Sinks/RichTextBoxForms/Themes/Theme.cs) class and passing it to the `RichTextBox` extension method. Look at the [existing themes](Serilog.Sinks.RichTextBox.WinForms.Colored/Sinks/RichTextBoxForms/Themes/ThemePresets.cs) for examples.
## Frequently Asked Questions
### Why is the package name so long?
Shorter alternatives were already reserved in the NuGet registry, so a more descriptive name was needed for this implementation. The name is a bit long, but it makes it easier to find the package in the NuGet registry.
### Why use a WinForms RichTextBox instead of a WPF RichTextBox?
This sink is specifically designed for WinForms applications to avoid the WPF framework. Using a WPF-based logging component would require adding the entire WPF framework with all its dependencies, greatly increasing the size of the application.
## Support and Contribute
If you find value in this project, there are several ways you can contribute:
- Give the [project](https://github.com/vonhoff/Serilog.Sinks.RichTextBox.WinForms.Colored) a star on GitHub ⭐
- Support the project through [GitHub Sponsors](https://github.com/sponsors/vonhoff)
- Improve documentation, report bugs, or submit pull requests
## License
Copyright © 2025 Simon Vonhoff & Contributors - Provided under the [Apache License, Version 2.0](LICENSE).