Skip to content

Handle Exception.ToString failures in text formatter#2197

Merged
nblumhardt merged 3 commits intoserilog:devfrom
krisbiradar:fix-vulnerable-tostring()-call
Sep 4, 2025
Merged

Handle Exception.ToString failures in text formatter#2197
nblumhardt merged 3 commits intoserilog:devfrom
krisbiradar:fix-vulnerable-tostring()-call

Conversation

@krisbiradar
Copy link
Copy Markdown
Contributor

closes #2165.

Wraps Exception.ToString in a try-catch block to prevent logging failures if the method throws. If an error occurs, a fallback message with details is written instead.

Wraps Exception.ToString in a try-catch block to prevent logging failures if the method throws. If an error occurs, a fallback message with details is written instead.
Copy link
Copy Markdown
Member

@nblumhardt nblumhardt left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Couple of minor comments.

@nblumhardt
Copy link
Copy Markdown
Member

Fantastic, thanks! I've just dug in, and Exception.Message is also virtual, so also may throw. It seems to fix the bug, all we'll be able to include in the formatted text is the exception type.

@nblumhardt
Copy link
Copy Markdown
Member

Thanks, Kris 👍

@nblumhardt nblumhardt merged commit 078de1e into serilog:dev Sep 4, 2025
1 check passed
@nblumhardt nblumhardt mentioned this pull request Feb 10, 2026
This was referenced Feb 10, 2026
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.

Exception in StackTrace leads to wrong message being logged

2 participants