Skip to content

Make WriteDiagnosticsToLog additive to the file or custom diagnostic writer#7722

Merged
danielmarbach merged 1 commit into
masterfrom
diagnostics
May 1, 2026
Merged

Make WriteDiagnosticsToLog additive to the file or custom diagnostic writer#7722
danielmarbach merged 1 commit into
masterfrom
diagnostics

Conversation

@danielmarbach
Copy link
Copy Markdown
Contributor

Follow up on #7660

As part of the work for Azure Functions we realize there are valid reasons to override the custom diagnostic writer to, for example, write the full information to blob storage and optionally write it to the log.

This is why we are making writing to log additive instead of exclusive. The functions default will disable the file writing by providing a no-op writer and customers can then opt-into custom writer themselves and/or writing to the logs.

@danielmarbach danielmarbach changed the title WriteDiagnosticsToLog is now additive to the file and custom diagnostic writer. Make WriteDiagnosticsToLog additive to the file or custom diagnostic writer Apr 29, 2026
Comment on lines +28 to +31
var logDictionary = new Dictionary<string, object>(dictionary, StringComparer.OrdinalIgnoreCase);
// Always compact AssemblyScanning section when writing to log
if (logDictionary.TryGetValue(AssemblyScanningDiagnostics.SectionName, out var assemblyScanningSection) &&
assemblyScanningSection is AssemblyScanningDiagnostics assemblyScanningDiagnostics)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't logDictionary always be a newly created dictionary and so logDictionary.TryGetValue() always return false?

I have to admit I am struggling to see (aside from this small bit) where this PR isn't just reorganizing some nesting levels and try/catch barriers. I don't understand how it's making anything additive. I have to be missing something.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DavidBoike The dictionary is a copy containing the values of the root dictionary created above which contains all the sections.

I don't understand how it's making anything additive. I have to be missing something.

Previously there was a return statement in there.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see the difference now. Thanks!

@danielmarbach danielmarbach requested a review from DavidBoike May 1, 2026 14:39
@danielmarbach danielmarbach merged commit acdc1d4 into master May 1, 2026
4 checks passed
@danielmarbach danielmarbach deleted the diagnostics branch May 1, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants