Skip to content

This library provides a LogTextBox and a TextBoxSink to be used with Serilog in wpf.

License

Notifications You must be signed in to change notification settings

imlokesh/SerilogTextBox

Repository files navigation

SerilogTextBox

This library provides a LogTextBox and a TextBoxSink to be used with Serilog in wpf. By default, LogTextBox will autoscroll if the caret is at the end of the textbox or vertical scrollbar is scrolled all the way to bottom.

SerilogTextBox Sample App

 

Getting Started

Here's a super quick start guide. For a more in depth example using MVVM pattern, check out the sample app.

  1. Create a new WPF application and install SerilogTextBox from nuget.

  2. Add the following code to your MainWindow.xaml.cs.

public partial class MainWindow : Window
{
    public TextBoxSink LogSink { get; set; }

    private Timer LogTimer { get; set; }

    public MainWindow()
    {
        InitializeComponent();
        DataContext = this;

        LogSink = new TextBoxSink();

        // Setup Serilog with TextBoxSink
        Log.Logger = new LoggerConfiguration()
                        .WriteTo
                        .TextBox(LogSink)
                        .CreateLogger();

        // Log every 500ms
        LogTimer = new Timer(c => Log.Information(Guid.NewGuid().ToString()), null, 1000, 500);
    }
}
  1. Add the LogTextBox control to your MainWindow.xaml.
<Window ...
		xmlns:stb="http://imlokesh.com/serilog/textbox"
        ...>
    <Grid>
        <stb:LogTextBox TextBoxSink="{Binding LogSink}" />
    </Grid>
</Window>
  1. Press F5 and you'll have a wpf application with a log message every 500ms in an autoscrolling log text box.

About

This library provides a LogTextBox and a TextBoxSink to be used with Serilog in wpf.

Topics

Resources

License

Stars

Watchers

Forks

Languages