Skip to content


Repository files navigation


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)

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()

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

    <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:

    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())


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.