Skip to content

Commit

Permalink
Maintain trace logging formats
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardneal committed Nov 1, 2024
1 parent 464b6f6 commit 39f1038
Showing 1 changed file with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ public void Initialize()
// transaction.
SqlInternalConnection connection = _connection;
SqlConnection usersConnection = connection.Connection;
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.Initialize | RES | CPOOL | Object Id {0}, Client Connection Id {1}, delegating transaction.", ObjectID, usersConnection?.ClientConnectionId);
#if NETFRAMEWORK
SqlClientEventSource.Log.TryTraceEvent("<sc.SqlDelegatedTransaction.Initialize|RES|CPOOL> {0}, Connection {1}, delegating transaction.", ObjectID, connection.ObjectID);
RuntimeHelpers.PrepareConstrainedRegions();
#else
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.Initialize | RES | CPOOL | Object Id {0}, Client Connection Id {1}, delegating transaction.", ObjectID, usersConnection?.ClientConnectionId);
#endif
try
{
Expand All @@ -98,7 +100,11 @@ public void Initialize()
#endif
if (connection.IsEnlistedInTransaction)
{
#if NETFRAMEWORK
SqlClientEventSource.Log.TryTraceEvent("<sc.SqlDelegatedTransaction.Initialize|RES|CPOOL> {0}, Connection {1}, was enlisted, now defecting.", ObjectID, connection.ObjectID);
#else
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.Initialize | RES | CPOOL | {0}, Client Connection Id {1}, was enlisted, now defecting.", ObjectID, usersConnection?.ClientConnectionId);
#endif

// defect first
connection.EnlistNull();
Expand Down Expand Up @@ -162,9 +168,11 @@ public byte[] Promote()
if (connection != null)
{
SqlConnection usersConnection = connection.Connection;
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.Promote | RES | CPOOL | Object Id {0}, Client Connection Id {1}, promoting transaction.", ObjectID, usersConnection?.ClientConnectionId);
#if NETFRAMEWORK
SqlClientEventSource.Log.TryTraceEvent("<sc.SqlDelegatedTransaction.Promote|RES|CPOOL> {0}, Connection {1}, promoting transaction.", ObjectID, connection.ObjectID);
RuntimeHelpers.PrepareConstrainedRegions();
#else
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.Promote | RES | CPOOL | Object Id {0}, Client Connection Id {1}, promoting transaction.", ObjectID, usersConnection?.ClientConnectionId);
#endif
try
{
Expand Down Expand Up @@ -269,13 +277,21 @@ public byte[] Promote()
else
{
// The transaction was aborted externally, since it's already doomed above, we only log the same.
#if NETFRAMEWORK
SqlClientEventSource.Log.TryTraceEvent("<sc.SqlDelegatedTransaction.Promote|RES|CPOOL> {0}, Connection {1}, aborted during promote.", ObjectID, connection.ObjectID);
#else
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.Promote | RES | CPOOL | Object Id {0}, Client Connection Id {1}, Aborted during promotion.", ObjectID, usersConnection?.ClientConnectionId);
#endif
}
}
else
{
// The transaction was aborted externally, doom the connection to make sure it's eventually rolled back and log the same.
#if NETFRAMEWORK
SqlClientEventSource.Log.TryTraceEvent("<sc.SqlDelegatedTransaction.Promote|RES|CPOOL> {0}, Connection null, aborted before promoting.", ObjectID);
#else
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.Promote | RES | CPOOL | {0}, Connection null, aborted before promoting.", ObjectID);
#endif
}
return returnValue;
}
Expand All @@ -293,9 +309,11 @@ public void Rollback(SinglePhaseEnlistment enlistment)
tdsReliabilitySection.Start();
#endif //DEBUG
SqlConnection usersConnection = connection.Connection;
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.Rollback | RES | CPOOL | Object Id {0}, Client Connection Id {1}, rolling back transaction.", ObjectID, usersConnection?.ClientConnectionId);
#if NETFRAMEWORK
RuntimeHelpers.PrepareConstrainedRegions();
SqlClientEventSource.Log.TryTraceEvent("<sc.SqlDelegatedTransaction.Rollback|RES|CPOOL> {0}, Connection {1}, rolling back transaction.", ObjectID, connection.ObjectID);
#else
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.Rollback | RES | CPOOL | Object Id {0}, Client Connection Id {1}, rolling back transaction.", ObjectID, usersConnection?.ClientConnectionId);
#endif
try
{
Expand Down Expand Up @@ -373,7 +391,11 @@ public void Rollback(SinglePhaseEnlistment enlistment)
{
// The transaction was aborted, report that to SysTx and log the same.
enlistment.Aborted();
#if NETFRAMEWORK
SqlClientEventSource.Log.TryTraceEvent("<sc.SqlDelegatedTransaction.Rollback|RES|CPOOL> {0}, Connection null, aborted before rollback.", ObjectID);
#else
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.Rollback | RES | CPOOL | Object Id {0}, Connection null, aborted before rollback.", ObjectID);
#endif
}
}

Expand All @@ -386,9 +408,11 @@ public void SinglePhaseCommit(SinglePhaseEnlistment enlistment)
if (connection != null)
{
SqlConnection usersConnection = connection.Connection;
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.SinglePhaseCommit | RES | CPOOL | Object Id {0}, Client Connection Id {1}, committing transaction.", ObjectID, usersConnection?.ClientConnectionId);
#if NETFRAMEWORK
SqlClientEventSource.Log.TryTraceEvent("<sc.SqlDelegatedTransaction.SinglePhaseCommit|RES|CPOOL> {0}, Connection {1}, committing transaction.", ObjectID, connection.ObjectID);
RuntimeHelpers.PrepareConstrainedRegions();
#else
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.SinglePhaseCommit | RES | CPOOL | Object Id {0}, Client Connection Id {1}, committing transaction.", ObjectID, usersConnection?.ClientConnectionId);
#endif

try
Expand Down Expand Up @@ -511,7 +535,11 @@ public void SinglePhaseCommit(SinglePhaseEnlistment enlistment)
{
// The transaction was aborted before we could commit, report that to SysTx and log the same.
enlistment.Aborted();
#if NETFRAMEWORK
SqlClientEventSource.Log.TryTraceEvent("<sc.SqlDelegatedTransaction.SinglePhaseCommit|RES|CPOOL> {0}, Connection null, aborted before commit.", ObjectID);
#else
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.SinglePhaseCommit | RES | CPOOL | Object Id {0}, Connection null, aborted before commit.", ObjectID);
#endif
}
}

Expand All @@ -525,7 +553,11 @@ internal void TransactionEnded(Transaction transaction)

if (connection != null)
{
#if NETFRAMEWORK
SqlClientEventSource.Log.TryTraceEvent("<sc.SqlDelegatedTransaction.TransactionEnded|RES|CPOOL> {0}, Connection {1}, transaction completed externally.", ObjectID, connection.ObjectID);
#else
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.TransactionEnded | RES | CPOOL | Object Id {0}, Connection Id {1}, transaction completed externally.", ObjectID, connection.ObjectID);
#endif
lock (connection)
{
if (_atomicTransaction.Equals(transaction))
Expand Down

0 comments on commit 39f1038

Please sign in to comment.