GithubHelp home page GithubHelp logo

umairsyed613 / serilog.sinks.winforms Goto Github PK

View Code? Open in Web Editor NEW
22.0 2.0 5.0 1.27 MB

Print Serilog logs from anywhere in you application into textbox or datagridview. windows forms

License: MIT License

C# 99.85% PowerShell 0.15%
serilog serilog-sink windows-forms serilog-windows-forms textbox datagridview nuget

serilog.sinks.winforms's Introduction

"Buy Me A Coffee"

Build Status

Build Status

Serilog.Sinks.WinForms (.net framework >= 4.6)

NuGet version Nuget

Serilog.Sinks.WinForms.Core (.net 5-6)

NuGet version Nuget

Writes Serilog events to Windows Froms Application TextBox or Datagridview control from anywhere in your application.

Getting started

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:

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.

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();
Json Formatted Log

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();
Datagridview Log

GridLog can be used from visual studio toolbox once the package is added to the project.

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

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

Sample Code

Find the sample running application here

Sample

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.