GithubHelp home page GithubHelp logo

serilog-contrib / serilog-sinks-exceldnalogdisplay Goto Github PK

View Code? Open in Web Editor NEW
13.0 2.0 5.0 269 KB

A Serilog sink that writes events to Excel-DNA LogDisplay

License: Apache License 2.0

C# 97.54% Batchfile 0.63% PowerShell 1.09% Shell 0.75%
serilog-sink serilog sink exceldna excel-dna logdisplay logging hacktoberfest augustoproiete

serilog-sinks-exceldnalogdisplay's Introduction

README.md
Serilog.Sinks.ExcelDnaLogDisplay

Serilog.Sinks.ExcelDnaLogDisplay

Writes Serilog events to Excel-DNA LogDisplay.

NuGet Version Stack Overflow Stack Overflow

Excel-DNA LogDisplay window screenshot

Give a Star! โญ

If you like or are using this project please give it a star. Thanks!

Getting started ๐Ÿš€

Install the Serilog.Sinks.ExcelDnaLogDisplay package from NuGet:

Install-Package Serilog.Sinks.ExcelDnaLogDisplay

To configure the sink in C# code, call WriteTo.ExcelDnaLogDisplay() during logger configuration:

var log = new LoggerConfiguration()
    .WriteTo.ExcelDnaLogDisplay(displayOrder: DisplayOrder.NewestFirst)
    .CreateLogger();

Example of an Excel-DNA add-in using Serilog with this sink

In the sample folder, there's an example of an Excel-DNA add-in that uses Serilog for logging to the LogDisplay of Excel-DNA using this sink, from different contexts, suchs as from an ExcelRibbon control event handler as well from an ExcelFunction:

Excel-DNA LogDisplay sample add-in ribbon screenshot

Excel-DNA LogDisplay sample add-in Excel function screenshot

XML <appSettings> configuration

To use the Excel-DNA LogDisplay sink with the Serilog.Settings.AppSettings package, first install that package if you haven't already done so:

Install-Package Serilog.Settings.AppSettings

Instead of configuring the logger in code, call ReadFrom.AppSettings():

var log = new LoggerConfiguration()
    .ReadFrom.AppSettings()
    .CreateLogger();

In your Excel-DNA Add-In's App.config, specify the Excel-DNA LogDisplay sink assembly under the <appSettings> node:

<configuration>
  <appSettings>
    <add key="serilog:using:ExcelDnaLogDisplay" value="Serilog.Sinks.ExcelDnaLogDisplay" />
    <add key="serilog:write-to:ExcelDnaLogDisplay" />

The parameters that can be set through the serilog:write-to:ExcelDnaLogDisplay keys are the method parameters accepted by the WriteTo.ExcelDnaLogDisplay() configuration method. This means, for example, that the displayOrder parameter can be set with:

    <add key="serilog:write-to:ExcelDnaLogDisplay.displayOrder" value="NewestFirst" />

Controlling event formatting

The Excel-DNA LogDisplay sink creates events in a fixed text format by default:

2021-09-07 09:02:17.148 -03:00 [INF] HTTP GET / responded 200 in 1994 ms

The format is controlled using an output template, which the Excel-DNA LogDisplay sink configuration method accepts as an outputTemplate parameter.

The default format above corresponds to an output template like:

  .WriteTo.ExcelDnaLogDisplay(
    outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}")
JSON event formatting

To write events to the Excel-DNA LogDisplay in an alternative format such as JSON, pass an ITextFormatter as the first argument:

    // Install-Package Serilog.Formatting.Compact
    .WriteTo.ExcelDnaLogDisplay(new CompactJsonFormatter())

Auditing

The Excel-DNA LogDisplay sink can operate as an audit sink through AuditTo:

    .AuditTo.ExcelDnaLogDisplay(displayOrder: DisplayOrder.NewestFirst)

Excel-DNA configuration for packing with ExcelDnaPack

In order for the Excel-DNA LogDisplay sink to work from an add-in that was packaged using the ExcelDnaPack utility, you need to include references to Serilog.dll and Serilog.Sinks.ExcelDnaLogDisplay.dll in the .dna file of the add-in:

<DnaLibrary Name="My Add-In" RuntimeVersion="v4.0">
  <ExternalLibrary Path="MyAddIn.dll" ExplicitExports="false" LoadFromBytes="true" Pack="true" />

  <Reference Path="Serilog.dll" Pack="true" />
  <Reference Path="Serilog.Sinks.ExcelDnaLogDisplay.dll" Pack="true" />

Release History

Click on the Releases tab on GitHub.


Copyright ยฉ 2018-2023 C. Augusto Proiete & Contributors - Provided under the Apache License, Version 2.0.

serilog-sinks-exceldnalogdisplay's People

Contributors

augustoproiete avatar dependabot[bot] avatar gauravagrwal avatar github-actions[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

serilog-sinks-exceldnalogdisplay's Issues

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.