Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

serilog-contrib/serilog-sinks-richtextbox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

99 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README.md
Serilog.Sinks.RichTextBox.Wpf

Serilog.Sinks.RichTextBox.Wpf

ASerilog sink that writes log events to any WPFRichTextBox control with coloring and custom theme support.

NuGet Version.NET.NET Core.NET FrameworkStack 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 theSerilog.Sinks.RichTextBox.Wpf package from NuGet:

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

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

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

Then enable the sink usingWriteTo.RichTextBox():

Log.Logger=newLoggerConfiguration().WriteTo.RichTextBox(MyRichTextBox).CreateLogger();Log.Information("Hello, world!");

Log events will be written to theRichTextBox 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:

ThemeDescription
RichTextBoxTheme.NoneNo styling. Uses default styles applied to theRichTextBox control
RichTextBoxConsoleTheme.LiterateStyled to replicate the default theme ofSerilog.Sinks.Console;This is the default when no theme is specified
RichTextBoxConsoleTheme.GrayscaleA theme using only shades of gray, white, and black
RichTextBoxConsoleTheme.ColoredA theme based on the originalSerilog.Sinks.ColoredConsole sink

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

Output templates

The format of events to the RichTextBox can be modified using theoutputTemplate 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 likeTimestamp andLevel. Properties from events, including those attached usingenrichers, can also appear in the output template.

Release History

Click on theReleases tab on GitHub.


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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Contributors7

Languages


[8]ページ先頭

©2009-2025 Movatter.jp