Excel-DNA / ExcelDna

Excel-DNA - Free and easy .NET for Excel. This repository contains the core Excel-DNA library.
https://excel-dna.net
zlib License
1.3k stars 276 forks source link

Add support for structured logging for diagnostics #277

Open augustoproiete opened 4 years ago

augustoproiete commented 4 years ago

Excel-DNA's Diagnostic Logging feature allows the developer to configure a TraceListener that will be used by Excel-DNA to write diagnostic log messages, which can then be forwarded to any logging pipeline such as Serilog or NLog, for example, in order to consume / analyse these logs outside of the user's machine.

Unfortunately, the standard Trace feature that comes with .NET only does simple text logging and does not provide structured logging capabilities, and important information is lost by the time messages reach the logging pipeline.

image

It would be great if Excel-DNA moved away from Trace and added support for structured logging within its diagnostic logging, and provided an extension point for the developer to attach structured logging providers at run-time.

Ideally it should use Microsoft.Extensions.Logging which is the current standard for modern .NET apps.

n1l commented 4 years ago

What do you think about ETW?

augustoproiete commented 4 years ago

@n1l Are you suggesting we write logs directly to ETW from within Excel-DNA?

It's definitely possible, but I see ETW more as a possible "destination" for the logs, instead of a "source" for logs.

I think Excel-DNA should not decide where to write logs, and instead provide a mechanism that allows the user to plug-in any .NET logging library that he/she wants, such as Serilog or NLog, for example, and the logging library then decides where the logs are written based on configuration provided by the Excel Add-In.

That way, if the user wants logs to end up in ETW, they can do so via the integration provided by the logging library they are using.

e.g. image

Does that make sense?

The Trace mechanism used in Excel-DNA today already provides a way to get the pipeline above by implementing a custom TraceListener (see ExcelDna.Diagnostics.Serilog for example) that forwards logs to a logging library, but everything is written in plain text without preserving field names and values.

I think Microsoft.Extensions.Logging at the moment would be the best candidate for the logging API glue, replacing the Trace.

n1l commented 4 years ago

Yes It's absolutely does, and I definitely need to try it out, thx!