How To Leverage Logging in .NET 6+

80 views
Skip to first unread message

Terry Aney

unread,
Mar 22, 2025, 7:34:32 PM3/22/25
to Excel-DNA
I'm having some debugging issues on deployed machines that I need to gather some information and trying to figure out how to leverage the logging ExcelDNA provides.

I've tried looking at this Excel-DNA Logging Sample from the Samples repo, but it is for .NET Framework.

Reading the Excel-DNA Logging Configuration Guide, I tried adding an environment variable of EXCELDNA_DIAGNOSTICS_SOURCE_LEVEL=All and then I ran my addin (locally in VS), but I didn't see any log messages, so I don't think I'm understanding how to configure.

Ideally, I think I'd like to do exactly what the Logging Sample was suggesting.  Disable the 'default logging output target' and write my own implementation (still leveraging TraceListener??) that would call a .Log method on Serilog, NLog, or similar.

Are there any updated samples showing the direction I should take?

With the given Environment variable I set, would you expect that I'd see some logging or is additional setup required?

Thanks in advance.

Terry Aney

unread,
Mar 22, 2025, 7:46:00 PM3/22/25
to Excel-DNA
C. Augusto Proiete seems to have written something very close to what I would like to do as well, but it is written against .NET Framework and app.config add-in management.

Govert van Drimmelen

unread,
Mar 23, 2025, 1:56:43 PM3/23/25
to Excel-DNA
Hi Terry,

When targeting .NET core, Excel-DNA only has limited options for logging the Excel-DNA internals.
We no longer support the TraceListener approach that was available in the .NET Framework.

The .NET core logging options can be configured as environment variables or registry entries.
Configuration details are here: Excel-DNA Logging Configuration Guide | Excel-DNA

You probably need to set both a useful Source Level, as well as one of the output levels for Debugger, File or LogDisplay (and for the file option a file name)

-Govert 

Terry Aney

unread,
Mar 24, 2025, 10:03:04 AM3/24/25
to Excel-DNA
Screenshot 2025-03-24 090030.png

This is what I've set.  I restarted VS, then started a debug session but there is no log file in the folder after starting Excel, opening file, clicking ribbon and closing Excel.  I've tried the file name variable without a path as well and couldn't find the file (looking in \bin).

Anything else I need to set?

Govert van Drimmelen

unread,
Mar 24, 2025, 10:13:16 AM3/24/25
to exce...@googlegroups.com

Hi Terry,

 

Yes, you need to set the source level too.

 

-Govert

 

From: exce...@googlegroups.com <exce...@googlegroups.com> On Behalf Of Terry Aney
Sent: 24 March 2025 16:03
To: Excel-DNA <exce...@googlegroups.com>
Subject: [ExcelDna] Re: How To Leverage Logging in .NET 6+

 

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/exceldna/e7375118-f50a-4ea4-903c-e8e802aa561an%40googlegroups.com.

image001.png

Terry Aney

unread,
Mar 24, 2025, 2:00:17 PM3/24/25
to Excel-DNA
I thought the EXCELDNA_DIAGNOSTICTS_FILE_LEVEL what doing that.  I'll try setting the  EXCELDNA_DIAGNOSTICS_SOURCE_LEVEL as well.  Hopefully they'll end up in the file?
Reply all
Reply to author
Forward
0 new messages