Add Exception field to ETW logging event#125727
Draft
rosebyte wants to merge 1 commit intodotnet:mainfrom
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds exception text to the FormattedMessage ETW event emitted by Microsoft.Extensions.Logging.EventSource, so consumers of the formatted-message keyword can also see exception details.
Changes:
- Extend
LoggingEventSource.FormattedMessage(EventId 1) payload to include anExceptionstring field and bump event version. - Update
EventSourceLoggerto passexception?.ToString()(or empty string) into the formatted-message event. - Adjust existing tests to validate the new
Exceptionfield presence for formatted-message events.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/libraries/Microsoft.Extensions.Logging.EventSource/src/LoggingEventSource.cs | Adds Exception to the FormattedMessage event payload and bumps event version. |
| src/libraries/Microsoft.Extensions.Logging.EventSource/src/EventSourceLogger.cs | Populates the new Exception payload field when emitting formatted-message events. |
| src/libraries/Microsoft.Extensions.Logging.EventSource/tests/EventSourceLoggerTest.cs | Updates expectations to include the new Exception field in formatted-message event JSON. |
Comments suppressed due to low confidence (1)
src/libraries/Microsoft.Extensions.Logging.EventSource/src/LoggingEventSource.cs:163
FormattedMessagetreatsEventName/FormattedMessageas nullable and normalizes them tostring.Empty, but the newExceptionparameter is non-nullable and only guarded byDebug.Assert. For consistency and to avoid a potentialNullReferenceExceptionin release builds if any future caller passes null, consider makingExceptionnullable and normalizing it like the other optional strings.
string? EventName,
string? FormattedMessage,
string ActivityTraceId,
string ActivitySpanId,
string ActivityTraceFlags,
string Exception)
{
Debug.Assert(LoggerName != null);
Debug.Assert(ActivityTraceId != null);
Debug.Assert(ActivitySpanId != null);
Debug.Assert(ActivityTraceFlags != null);
Debug.Assert(Exception != null);
EventName ??= string.Empty;
FormattedMessage ??= string.Empty;
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
137
to
138
| /// FormattedMessage() is called when ILogger.Log() is called. and the FormattedMessage keyword is active | ||
| /// This only gives you the human readable formatted message. |
This was referenced Mar 18, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #43092
add Exception field to ETW event