Skip to content

Commit f62c3ca

Browse files
Add README.md
1 parent 7c623de commit f62c3ca

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

README.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
| README.md |
2+
|:---|
3+
4+
<div align="center">
5+
6+
<img src="asset/serilog-sink-nuget.png" alt="Serilog.Sinks.RichTextBox.Wpf" width="100" />
7+
8+
</div>
9+
10+
<h1 align="center">Serilog.Sinks.RichTextBox.Wpf</h1>
11+
<div align="center">
12+
13+
A [Serilog](https://serilog.net) sink that writes log events to any WPF [RichTextBox](https://docs.microsoft.com/en-us/dotnet/desktop/wpf/controls/richtextbox-overview?view=netframeworkdesktop-4.8) control with coloring and custom theme support.
14+
15+
[![NuGet Version](http://img.shields.io/nuget/v/Serilog.Sinks.RichTextBox.Wpf.svg?style=flat)](https://www.nuget.org/packages/Serilog.Sinks.RichTextBox.Wpf) [![.NET](https://img.shields.io/badge/.NET%20-%3E%3D%205.0-512bd4)](https://dotnet.microsoft.com/download) [![.NET Core](https://img.shields.io/badge/.NET%20Core-%3E%3D%203.1-512bd4)](https://dotnet.microsoft.com/download) [![.NET Framework](https://img.shields.io/badge/.NET%20Framework-%3E%3D%204.5-512bd4)](https://dotnet.microsoft.com/download) [![Stack Overflow](https://img.shields.io/badge/stack%20overflow-serilog-orange.svg)](http://stackoverflow.com/questions/tagged/serilog)
16+
17+
![Screenshot of Serilog.Sinks.RichTextBox.Wpf in action](asset/serilog-sinks-richtextbox-screenshot.png)
18+
19+
</div>
20+
21+
## Give a Star! :star:
22+
23+
If you like or are using this project please give it a star. Thanks!
24+
25+
## Getting started :rocket:
26+
27+
Install the [Serilog.Sinks.RichTextBox.Wpf](https://www.nuget.org/packages/Serilog.Sinks.RichTextBox.Wpf) package from NuGet:
28+
29+
```powershell
30+
Install-Package Serilog.Sinks.RichTextBox.Wpf
31+
```
32+
33+
Declare your [RichTextBox](https://docs.microsoft.com/en-us/dotnet/desktop/wpf/controls/richtextbox-overview?view=netframeworkdesktop-4.8) control and give it a name that you can reference it from the code-behind. e.g.:
34+
35+
```xml
36+
<Window (...)>
37+
<RichTextBox
38+
x:Name="MyRichTextBox"
39+
Background="Black"
40+
Foreground="LightGray"
41+
FontFamily="Cascadia Mono, Consolas, Courier New, monospace"
42+
VerticalScrollBarVisibility="Auto"
43+
/>
44+
</Window>
45+
```
46+
47+
Then enable the sink using `WriteTo.RichTextBox()`:
48+
49+
```csharp
50+
Log.Logger = new LoggerConfiguration()
51+
.WriteTo.RichTextBox(MyRichTextBox)
52+
.CreateLogger();
53+
54+
Log.Information("Hello, world!");
55+
```
56+
57+
Log events will be written to the `RichTextBox` control:
58+
59+
```
60+
[11:54:36 INF] Hello, world!
61+
```
62+
63+
### Themes
64+
65+
The sink will colorize output by default:
66+
67+
![Screenshot of Serilog.Sinks.RichTextBox.Wpf in action](asset/serilog-sinks-richtextbox-screenshot.png)
68+
69+
Themes can be specified when configuring the sink:
70+
71+
```csharp
72+
.WriteTo.RichTextBox(MyRichTextBox, theme: RichTextBoxConsoleTheme.Grayscale)
73+
```
74+
75+
The following built-in themes are available at this time:
76+
77+
| Theme | Description
78+
| ----------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
79+
| `RichTextBoxTheme.None` | No styling. Uses default styles applied to the `RichTextBox` control |
80+
| `RichTextBoxConsoleTheme.Literate` | Styled to replicate the default theme of _Serilog.Sinks.Console_; **This is the default when no theme is specified** |
81+
| `RichTextBoxConsoleTheme.Grayscale` | A theme using only shades of gray, white, and black |
82+
| `RichTextBoxConsoleTheme.Colored` | A theme based on the original `Serilog.Sinks.ColoredConsole` sink |
83+
84+
Adding a new theme is straightforward; examples can be found in the [`RichTextBoxConsoleThemes`](src/Serilog.Sinks.RichTextBox.Wpf/Sinks/RichTextBox/Themes/RichTextBoxConsoleThemes.cs) class.
85+
86+
### Output templates
87+
88+
The format of events to the RichTextBox can be modified using the `outputTemplate` configuration parameter:
89+
90+
```csharp
91+
.WriteTo.RichTextBox(MyRichTextBox,
92+
outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
93+
```
94+
95+
The default template, shown in the example above, uses built-in properties like `Timestamp` and `Level`. Properties from events, including those attached using [enrichers](https://github.com/serilog/serilog/wiki/Enrichment), can also appear in the output template.
96+
97+
## Release History
98+
99+
Click on the [Releases](https://github.com/augustoproiete/serilog-sinks-richtextbox/releases) tab on GitHub.
100+
101+
---
102+
103+
_Copyright &copy; 2021 C. Augusto Proiete & Contributors - Provided under the [Apache License, Version 2.0](LICENSE)._
52.9 KB
Loading

serilog-sinks-richtextbox.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "asset", "asset", "{10468526
3333
global.json = global.json
3434
LICENSE = LICENSE
3535
nuget.config = nuget.config
36+
README.md = README.md
3637
EndProjectSection
3738
EndProject
3839
Global

0 commit comments

Comments
 (0)