Writes Serilog events to Windows Froms Application TextBox or Datagridview control from anywhere in your application.
Install the Serilog.Sinks.WinForms package from NuGet:
Install-Package Serilog.Sinks.WinForms
Install the Serilog.Sinks.WinForms.Core package from NuGet:
Install-Package Serilog.Sinks.WinForms.Core
To configure the sink in C# code, call WriteToSimpleAndRichTextBox()
or WriteToJsonTextBox()
or WriteToGridView()
during logger configuration:
SimpleLogTextBox or RichTextBoxLogControl can be used from visual studio toolbox once the package is added to the project.
Log.Logger = new LoggerConfiguration()
.WriteToSimpleAndRichTextBox()
.CreateLogger();
SimpleLogTextBox or RichTextBoxLogControl with custom Configuration. SimpleLogTextBox accepts ITextFormatter
Log.Logger = new LoggerConfiguration()
.WriteToSimpleAndRichTextBox(new MessageTemplateTextFormatter("{Timestamp} [{Level}] {Message} {Exception}"))
.CreateLogger();
JsonLogTextBox can be used from visual studio toolbox once the package is added to the project.
Log.Logger = new LoggerConfiguration()
.WriteToJsonTextBox()
.CreateLogger();
JsonLogTextBox with custom Configuration. JsonLogTextBox accepts ITextFormatter
Log.Logger = new LoggerConfiguration()
.WriteToJsonTextBox(new JsonFormatter())
.CreateLogger();
GridLog can be used from visual studio toolbox once the package is added to the project.
Log.Logger = new LoggerConfiguration()
.WriteToGridView()
.CreateLogger();
SimpleLogTextBox, RichTextBoxLogControl or JsonLogTextBox can be configured to display log for specific Context. All of the controls have property For Context which can be configured with namespace.classname for example TestApplication.Form2 you can find the sample here >> Sample
Note: Remember to configure Logger instance with Enrich.FromLogContext()
SimpleLogTextBox, RichTextBoxLogControl or JsonLogTextBox have two method available for saving log to file or clear the log from the log control. ClearLogs() AND SaveLogToFile()
Check the usage in sample application here Sample
Find the sample running application here