Skip to content

Keep logging commands after a command fails - #39498

Merged
AndriySvyryd merged 1 commit into
dotnet:mainfrom
AsadIqbal-Dev:fix/log-commands-after-error
Nov 3, 2026
Merged

AndriySvyryd merged 1 commit into
dotnet:mainfrom
AsadIqbal-Dev:fix/log-commands-after-error

Conversation

@AsadIqbal-Dev

Copy link
Copy Markdown
Contributor
  • I've read the guidelines for contributing and seen the walkthrough
  • I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • The code builds and tests pass locally (also verified by our automated build checks)
  • Commit messages follow this format
  • Tests for the changes have been added (for bug fixes / features)
  • Code follows the same patterns and style as existing code in this repo

Fixes #32244

The *Executing methods set _suppressCommandExecuteExpiration to startTime + LoggingCacheTime, and the *Executed methods clear it when the executed event is enabled. A command that fails or is canceled never reaches *Executed, so the expiry stays set and ShouldLogCommandExecute returns false until it runs out. At Information level that loses the CommandExecuted entries of the commands after the failure, for up to a second by default. Debug logging hides it because *Executing clears the expiry itself.

CommandError and CommandCanceled, sync and async, now clear the expiry. If nobody is listening, the only cost is that the next command takes the logging path once and sets the expiry again.

Tests:

  • RelationalCommandTest: Logging_is_not_suppressed_after_exception and Logging_is_not_suppressed_after_cancellation, for non-query, scalar and reader, sync and async.
  • LoggingSqliteTest.Commands_are_logged_after_a_command_fails: the reported scenario on SQLite, sync and async.

All of them fail without the change. EFCore.Relational.Tests and LoggingSqliteTest pass with it.

- Clear the command execute suppression in CommandError and CommandCanceled, since CommandExecuted won't run for that command
- Add tests for each execute method and for the reported scenario on SQLite

Fixes dotnet#32244

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain, and the change is supported by targeted regression coverage for synchronous and asynchronous failure and cancellation paths.

No open issues 🎉

What changed in this PR

This pull request fixes relational command logging suppression after a command fails or is canceled, ensuring subsequent commands are logged immediately.

Changes:

  • Clear command-execution logging suppression across synchronous and asynchronous error and cancellation paths.
  • Add relational regression tests for non-query, scalar, and reader commands in sync and async scenarios.
  • Add a SQLite functional test confirming commands remain logged after a failure.
File Description
test/​EFCore.Sqlite.FunctionalTests/​LoggingSqliteTest.cs Verifies subsequent SQLite commands are logged after a failure.
test/​EFCore.Relational.Tests/​Storage/​RelationalCommandTest.cs Tests suppression reset across command execution methods and execution modes.
src/​EFCore.Relational/​Diagnostics/​Internal/​RelationalCommandDiagnosticsLogger.cs Resets command logging suppression after errors and cancellations.

Review effort: Lite

@AndriySvyryd AndriySvyryd left a comment

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.

Thanks for your contribution!

@AndriySvyryd
AndriySvyryd merged commit c5916ed into dotnet:main Nov 3, 2026
19 of 20 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logging of RelationalCommands stops for up to 1000ms once a command errors

3 participants