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.
I wonder if the problem you are hitting is related to https://github.com/aspnet/EntityFramework6/issues/22. In any case, it would be great if you could report this as an issue in https://github.com/aspnet/EntityFramework6/issues/.