Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/umairsyed613/serilog.sinks.winforms
Print Serilog logs from anywhere in you application into textbox or datagridview. windows forms
https://github.com/umairsyed613/serilog.sinks.winforms
datagridview nuget serilog serilog-sink serilog-windows-forms textbox windows-forms
Last synced: 3 months ago
JSON representation
Print Serilog logs from anywhere in you application into textbox or datagridview. windows forms
- Host: GitHub
- URL: https://github.com/umairsyed613/serilog.sinks.winforms
- Owner: umairsyed613
- License: mit
- Created: 2020-08-20T13:39:12.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-09-02T09:55:43.000Z (over 2 years ago)
- Last Synced: 2024-11-07T08:03:23.256Z (3 months ago)
- Topics: datagridview, nuget, serilog, serilog-sink, serilog-windows-forms, textbox, windows-forms
- Language: C#
- Homepage:
- Size: 1.24 MB
- Stars: 23
- Watchers: 2
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/umairsyed613)
## Build Status
![Build Status](https://travis-ci.org/umairsyed613/Serilog.Sinks.WinForms.svg?branch=master)
# Serilog.Sinks.WinForms (.net framework >= 4.6)
[![NuGet version](https://badge.fury.io/nu/Serilog.Sinks.WinForms.png)](https://badge.fury.io/nu/Serilog.Sinks.WinForms) [![Nuget](https://img.shields.io/nuget/dt/Serilog.Sinks.WinForms)](https://www.nuget.org/packages/Serilog.Sinks.WinForms)
# Serilog.Sinks.WinForms.Core (.net 5-6)
[![NuGet version](https://badge.fury.io/nu/Serilog.Sinks.WinForms.Core.png)](https://badge.fury.io/nu/Serilog.Sinks.WinForms.Core) [![Nuget](https://img.shields.io/nuget/dt/Serilog.Sinks.WinForms.Core)](https://www.nuget.org/packages/Serilog.Sinks.WinForms.Core)
Writes [Serilog](https://serilog.net) events to Windows Froms Application TextBox or Datagridview control from anywhere in your application.
### Getting started
Install the [Serilog.Sinks.WinForms](https://www.nuget.org/packages/Serilog.Sinks.WinForms/) package from NuGet:
```powershell
Install-Package Serilog.Sinks.WinForms
```Install the [Serilog.Sinks.WinForms.Core](https://www.nuget.org/packages/Serilog.Sinks.WinForms.Core/) package from NuGet:
```powershell
Install-Package Serilog.Sinks.WinForms.Core
```To configure the sink in C# code, call `WriteToSimpleAndRichTextBox()` or `WriteToJsonTextBox()` or `WriteToGridView()` during logger configuration:
##### Simple Text Formatted Log And Rich TextBox Log Control
SimpleLogTextBox or RichTextBoxLogControl can be used from visual studio toolbox once the package is added to the project.
```csharp
Log.Logger = new LoggerConfiguration()
.WriteToSimpleAndRichTextBox()
.CreateLogger();
```SimpleLogTextBox or RichTextBoxLogControl with custom Configuration. SimpleLogTextBox accepts [ITextFormatter](https://github.com/serilog/serilog/blob/dev/src/Serilog/Formatting/ITextFormatter.cs)
```csharp
Log.Logger = new LoggerConfiguration()
.WriteToSimpleAndRichTextBox(new MessageTemplateTextFormatter("{Timestamp} [{Level}] {Message} {Exception}"))
.CreateLogger();
```##### Json Formatted Log
JsonLogTextBox can be used from visual studio toolbox once the package is added to the project.
```csharp
Log.Logger = new LoggerConfiguration()
.WriteToJsonTextBox()
.CreateLogger();
```JsonLogTextBox with custom Configuration. JsonLogTextBox accepts [ITextFormatter](https://github.com/serilog/serilog/blob/dev/src/Serilog/Formatting/ITextFormatter.cs)
```csharp
Log.Logger = new LoggerConfiguration()
.WriteToJsonTextBox(new JsonFormatter())
.CreateLogger();
```##### Datagridview Log
GridLog can be used from visual studio toolbox once the package is added to the project.
```csharp
Log.Logger = new LoggerConfiguration()
.WriteToGridView()
.CreateLogger();
```#### Log For Context
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](https://github.com/umairsyed613/Serilog.Sinks.WinForms/blob/master/src/Sample/TestApplication/Form2.cs)**Note:** Remember to configure Logger instance with ***Enrich.FromLogContext()***
#### Save and Clear Logs
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](https://github.com/umairsyed613/Serilog.Sinks.WinForms/blob/master/src/Sample/TestApplication/Form2.cs)
### Sample Code
Find the sample running application [here](https://github.com/umairsyed613/Serilog.Sinks.WinForms/tree/master/Sample/TestApplication/)
![Sample](https://github.com/umairsyed613/Serilog.Sinks.WinForms/blob/main/SampleVideo.gif)