Search for existing suggestions

Provide a way to include transaction information in EF logging

We're able to log the commands that EF is executing, by setting a delegate on DbContext.Database.Log.

When you do this, you see "Started Transaction at ..." and "Committed Transaction at ..." messages.

From this, you'd think you could determine the duration of the transactions. You can't. When load becomes high enough for transactions to begin to overlap, there is no way to match the start and commit transaction messages.

We're able to manipulate the text of the messages that are being logged by deriving a class from DatabaseLogFormatter.

Within DatabaseLogFormatter.LogCommand() we have access to the DbCommand, and through DbCommand.Transaction to the DbTransaction that the command is part of. This allows us to create an identifier for the transaction using ObjectIDGenerator, and to include it in the message.

Unfortunately, the "Started Transaction" and "Committed Transaction" messages aren't processed through the DatabaseLogFormatter. They are simply written to the log directly.

What we need is to have information about what transaction each SQL statement was a part of, to include the started transaction and committed transaction messages.

Right now, I see no way of accomplishing this.

1 vote
Sign in
(thinking…)
Password icon
Signed in as (Sign out)

We’ll send you updates on this idea

jdege shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

1 comment

Sign in
(thinking…)
Password icon
Signed in as (Sign out)
Submitting...

Feedback and Knowledge Base