| README.md |
|---|
If you like or are using this project please give it a star. Thanks!
Install the Serilog.Sinks.ExcelDnaLogDisplay package from NuGet:
Install-Package Serilog.Sinks.ExcelDnaLogDisplayTo configure the sink in C# code, call WriteTo.ExcelDnaLogDisplay() during logger configuration:
var log = new LoggerConfiguration()
.WriteTo.ExcelDnaLogDisplay(displayOrder: DisplayOrder.NewestFirst)
.CreateLogger();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:
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.AppSettingsInstead 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" />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}")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())The Excel-DNA LogDisplay sink can operate as an audit sink through AuditTo:
.AuditTo.ExcelDnaLogDisplay(displayOrder: DisplayOrder.NewestFirst)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" />Click on the Releases tab on GitHub.
Copyright © 2018-2023 C. Augusto Proiete & Contributors - Provided under the Apache License, Version 2.0.



