Skip to content

Commit 29b65c0

Browse files
Standardization of Event Source tracing + Improvements for readability (#484)
1 parent 2874114 commit 29b65c0

File tree

71 files changed

+1997
-1577
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1997
-1577
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/Common/DbConnectionOptions.Common.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ private static bool CompareInsensitiveInvariant(string strvalue, string strconst
161161
[System.Diagnostics.Conditional("DEBUG")]
162162
private static void DebugTraceKeyValuePair(string keyname, string keyvalue, Dictionary<string, string> synonyms)
163163
{
164-
if (SqlClientEventSource.Log.IsAdvanceTraceOn())
164+
if (SqlClientEventSource.Log.IsAdvancedTraceOn())
165165
{
166166
Debug.Assert(string.Equals(keyname, keyname?.ToLower(), StringComparison.InvariantCulture), "missing ToLower");
167167
string realkeyname = ((null != synonyms) ? (string)synonyms[keyname] : keyname);
@@ -171,11 +171,11 @@ private static void DebugTraceKeyValuePair(string keyname, string keyvalue, Dict
171171
// don't trace passwords ever!
172172
if (null != keyvalue)
173173
{
174-
SqlClientEventSource.Log.AdvanceTrace("<comm.DbConnectionOptions|INFO|ADV> KeyName='{0}', KeyValue='{1}'", keyname, keyvalue);
174+
SqlClientEventSource.Log.AdvancedTraceEvent("<comm.DbConnectionOptions|INFO|ADV> KeyName='{0}', KeyValue='{1}'", keyname, keyvalue);
175175
}
176176
else
177177
{
178-
SqlClientEventSource.Log.AdvanceTrace("<comm.DbConnectionOptions|INFO|ADV> KeyName='{0}'", keyname);
178+
SqlClientEventSource.Log.AdvancedTraceEvent("<comm.DbConnectionOptions|INFO|ADV> KeyName='{0}'", keyname);
179179
}
180180
}
181181
}

src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ abstract public DbProviderFactory ProviderFactory
4949

5050
public void ClearAllPools()
5151
{
52-
long scopeID = SqlClientEventSource.Log.ScopeEnterEvent("<prov.DbConnectionFactory.ClearAllPools|{0}>", "API");
52+
long scopeID = SqlClientEventSource.Log.ScopeEnterEvent("<prov.DbConnectionFactory.ClearAllPools|API");
5353
try
5454
{
5555
Dictionary<DbConnectionPoolKey, DbConnectionPoolGroup> connectionPoolGroups = _connectionPoolGroups;
@@ -71,7 +71,7 @@ public void ClearAllPools()
7171
public void ClearPool(DbConnection connection)
7272
{
7373
ADP.CheckArgumentNull(connection, nameof(connection));
74-
long scopeID = SqlClientEventSource.Log.ScopeEnterEvent("<prov.DbConnectionFactory.ClearPool|API> {0}#", GetObjectId(connection));
74+
long scopeID = SqlClientEventSource.Log.ScopeEnterEvent("<prov.DbConnectionFactory.ClearPool|API> {0}", GetObjectId(connection));
7575
try
7676
{
7777
DbConnectionPoolGroup poolGroup = GetConnectionPoolGroup(connection);
@@ -126,7 +126,7 @@ internal DbConnectionInternal CreateNonPooledConnection(DbConnection owningConne
126126
{
127127
newConnection.MakeNonPooledObject(owningConnection);
128128
}
129-
SqlClientEventSource.Log.TraceEvent("<prov.DbConnectionFactory.CreateNonPooledConnection|RES|CPOOL> {0}#, Non-pooled database connection created.", ObjectID);
129+
SqlClientEventSource.Log.TraceEvent("<prov.DbConnectionFactory.CreateNonPooledConnection|RES|CPOOL> {0}, Non-pooled database connection created.", ObjectID);
130130
return newConnection;
131131
}
132132

@@ -140,7 +140,7 @@ internal DbConnectionInternal CreatePooledConnection(DbConnectionPool pool, DbCo
140140
{
141141
newConnection.MakePooledConnection(pool);
142142
}
143-
SqlClientEventSource.Log.TraceEvent("<prov.DbConnectionFactory.CreatePooledConnection|RES|CPOOL> {0}#, Pooled database connection created.", ObjectID);
143+
SqlClientEventSource.Log.TraceEvent("<prov.DbConnectionFactory.CreatePooledConnection|RES|CPOOL> {0}, Pooled database connection created.", ObjectID);
144144
return newConnection;
145145
}
146146

@@ -195,7 +195,7 @@ private DbConnectionPool GetConnectionPool(DbConnection owningObject, DbConnecti
195195
// however, don't rebuild connectionOptions if no pooling is involved - let new connections do that work
196196
if (connectionPoolGroup.IsDisabled && (null != connectionPoolGroup.PoolGroupOptions))
197197
{
198-
SqlClientEventSource.Log.TraceEvent("<prov.DbConnectionFactory.GetConnectionPool|RES|INFO|CPOOL> {0}#, DisabledPoolGroup={1}#", ObjectID, connectionPoolGroup.ObjectID);
198+
SqlClientEventSource.Log.TraceEvent("<prov.DbConnectionFactory.GetConnectionPool|RES|INFO|CPOOL> {0}, DisabledPoolGroup={1}", ObjectID, connectionPoolGroup.ObjectID);
199199

200200
// reusing existing pool option in case user originally used SetConnectionPoolOptions
201201
DbConnectionPoolGroupOptions poolOptions = connectionPoolGroup.PoolGroupOptions;
@@ -303,7 +303,7 @@ internal DbConnectionPoolGroup GetConnectionPoolGroup(DbConnectionPoolKey key, D
303303
private void PruneConnectionPoolGroups(object state)
304304
{
305305
// when debugging this method, expect multiple threads at the same time
306-
SqlClientEventSource.Log.AdvanceTrace("<prov.DbConnectionFactory.PruneConnectionPoolGroups|RES|INFO|CPOOL> {0}#", ObjectID);
306+
SqlClientEventSource.Log.AdvancedTraceEvent("<prov.DbConnectionFactory.PruneConnectionPoolGroups|RES|INFO|CPOOL> {0}", ObjectID);
307307

308308
// First, walk the pool release list and attempt to clear each
309309
// pool, when the pool is finally empty, we dispose of it. If the
@@ -323,7 +323,7 @@ private void PruneConnectionPoolGroups(object state)
323323
if (0 == pool.Count)
324324
{
325325
_poolsToRelease.Remove(pool);
326-
SqlClientEventSource.Log.AdvanceTrace("<prov.DbConnectionFactory.PruneConnectionPoolGroups|RES|INFO|CPOOL> {0}#, ReleasePool={1}#", ObjectID, pool.ObjectID);
326+
SqlClientEventSource.Log.AdvancedTraceEvent("<prov.DbConnectionFactory.PruneConnectionPoolGroups|RES|INFO|CPOOL> {0}, ReleasePool={1}", ObjectID, pool.ObjectID);
327327
}
328328
}
329329
}
@@ -347,7 +347,7 @@ private void PruneConnectionPoolGroups(object state)
347347
if (0 == poolsLeft)
348348
{
349349
_poolGroupsToRelease.Remove(poolGroup);
350-
SqlClientEventSource.Log.AdvanceTrace("<prov.DbConnectionFactory.PruneConnectionPoolGroups|RES|INFO|CPOOL> {0}#, ReleasePoolGroup={1}#", ObjectID, poolGroup.ObjectID);
350+
SqlClientEventSource.Log.AdvancedTraceEvent("<prov.DbConnectionFactory.PruneConnectionPoolGroups|RES|INFO|CPOOL> {0}, ReleasePoolGroup={1}", ObjectID, poolGroup.ObjectID);
351351
}
352352
}
353353
}
@@ -410,7 +410,7 @@ internal void QueuePoolForRelease(DbConnectionPool pool, bool clearing)
410410
internal void QueuePoolGroupForRelease(DbConnectionPoolGroup poolGroup)
411411
{
412412
Debug.Assert(null != poolGroup, "null poolGroup?");
413-
SqlClientEventSource.Log.TraceEvent("<prov.DbConnectionFactory.QueuePoolGroupForRelease|RES|INFO|CPOOL> {0}#, poolGroup={1}#", ObjectID, poolGroup.ObjectID);
413+
SqlClientEventSource.Log.TraceEvent("<prov.DbConnectionFactory.QueuePoolGroupForRelease|RES|INFO|CPOOL> {0}, poolGroup={1}", ObjectID, poolGroup.ObjectID);
414414

415415
lock (_poolGroupsToRelease)
416416
{

src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ internal void DeactivateConnection()
225225
{
226226
// Internal method called from the connection pooler so we don't expose
227227
// the Deactivate method publicly.
228-
SqlClientEventSource.Log.PoolerTraceEvent("<prov.DbConnectionInternal.DeactivateConnection|RES|INFO|CPOOL> {0}#, Deactivating", ObjectID);
228+
SqlClientEventSource.Log.PoolerTraceEvent("<prov.DbConnectionInternal.DeactivateConnection|RES|INFO|CPOOL> {0}, Deactivating", ObjectID);
229229

230230
#if DEBUG
231231
int activateCount = Interlocked.Decrement(ref _activateCount);
@@ -249,14 +249,14 @@ internal void DeactivateConnection()
249249
protected internal void DoNotPoolThisConnection()
250250
{
251251
_cannotBePooled = true;
252-
SqlClientEventSource.Log.PoolerTraceEvent("<prov.DbConnectionInternal.DoNotPoolThisConnection|RES|INFO|CPOOL> {0}#, Marking pooled object as non-poolable so it will be disposed", ObjectID);
252+
SqlClientEventSource.Log.PoolerTraceEvent("<prov.DbConnectionInternal.DoNotPoolThisConnection|RES|INFO|CPOOL> {0}, Marking pooled object as non-poolable so it will be disposed", ObjectID);
253253
}
254254

255255
/// <devdoc>Ensure that this connection cannot be put back into the pool.</devdoc>
256256
protected internal void DoomThisConnection()
257257
{
258258
_connectionIsDoomed = true;
259-
SqlClientEventSource.Log.PoolerTraceEvent("<prov.DbConnectionInternal.DoomThisConnection|RES|INFO|CPOOL> {0}#, Dooming", ObjectID);
259+
SqlClientEventSource.Log.PoolerTraceEvent("<prov.DbConnectionInternal.DoomThisConnection|RES|INFO|CPOOL> {0}, Dooming", ObjectID);
260260
}
261261

262262
protected internal virtual DataTable GetSchema(DbConnectionFactory factory, DbConnectionPoolGroup poolGroup, DbConnection outerConnection, string collectionName, string[] restrictions)
@@ -377,7 +377,7 @@ internal void PrePush(object expectedOwner)
377377
throw ADP.InternalError(ADP.InternalErrorCode.PushingObjectSecondTime); // pushing object onto stack a second time
378378
}
379379

380-
SqlClientEventSource.Log.PoolerTraceEvent("<prov.DbConnectionInternal.PrePush|RES|CPOOL> {0}#, Preparing to push into pool, owning connection {1}#, pooledCount={2}", ObjectID, 0, _pooledCount);
380+
SqlClientEventSource.Log.PoolerTraceEvent("<prov.DbConnectionInternal.PrePush|RES|CPOOL> {0}, Preparing to push into pool, owning connection {1}, pooledCount={2}", ObjectID, 0, _pooledCount);
381381
_pooledCount++;
382382
_owningObject.Target = null; // NOTE: doing this and checking for InternalError.PooledObjectHasOwner degrades the close by 2%
383383
}
@@ -406,7 +406,7 @@ internal void PostPop(object newOwner)
406406
}
407407
_owningObject.Target = newOwner;
408408
_pooledCount--;
409-
SqlClientEventSource.Log.PoolerTraceEvent("<prov.DbConnectionInternal.PostPop|RES|CPOOL> {0}#, Preparing to pop from pool, owning connection {1}#, pooledCount={2}", ObjectID, 0, _pooledCount);
409+
SqlClientEventSource.Log.PoolerTraceEvent("<prov.DbConnectionInternal.PostPop|RES|CPOOL> {0}, Preparing to pop from pool, owning connection {1}, pooledCount={2}", ObjectID, 0, _pooledCount);
410410

411411
//3 // The following tests are retail assertions of things we can't allow to happen.
412412
if (null != Pool)

src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/ProviderBase/DbConnectionPoolGroup.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private bool MarkPoolGroupAsActive()
229229
if (PoolGroupStateIdle == _state)
230230
{
231231
_state = PoolGroupStateActive;
232-
SqlClientEventSource.Log.TraceEvent("<prov.DbConnectionPoolGroup.ClearInternal|RES|INFO|CPOOL> {0}#, Active", ObjectID);
232+
SqlClientEventSource.Log.TraceEvent("<prov.DbConnectionPoolGroup.ClearInternal|RES|INFO|CPOOL> {0}, Active", ObjectID);
233233
}
234234
return (PoolGroupStateActive == _state);
235235
}
@@ -281,12 +281,12 @@ internal bool Prune()
281281
if (PoolGroupStateActive == _state)
282282
{
283283
_state = PoolGroupStateIdle;
284-
SqlClientEventSource.Log.TraceEvent("<prov.DbConnectionPoolGroup.ClearInternal|RES|INFO|CPOOL> {0}#, Idle", ObjectID);
284+
SqlClientEventSource.Log.TraceEvent("<prov.DbConnectionPoolGroup.ClearInternal|RES|INFO|CPOOL> {0}, Idle", ObjectID);
285285
}
286286
else if (PoolGroupStateIdle == _state)
287287
{
288288
_state = PoolGroupStateDisabled;
289-
SqlClientEventSource.Log.TraceEvent("<prov.DbConnectionPoolGroup.ReadyToRemove|RES|INFO|CPOOL> {0}#, Disabled", ObjectID);
289+
SqlClientEventSource.Log.TraceEvent("<prov.DbConnectionPoolGroup.ReadyToRemove|RES|INFO|CPOOL> {0}, Disabled", ObjectID);
290290
}
291291
}
292292
return (PoolGroupStateDisabled == _state);

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/DataException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ static private void TraceException(
3131
Debug.Assert(null != e, "TraceException: null Exception");
3232
if (null != e)
3333
{
34-
SqlClientEventSource.Log.AdvanceTrace(trace, e.Message);
35-
SqlClientEventSource.Log.AdvanceTrace("<comm.ADP.TraceException|ERR|ADV> Environment StackTrace = '{0}'", Environment.StackTrace);
34+
SqlClientEventSource.Log.AdvancedTraceEvent(trace, e.Message);
35+
SqlClientEventSource.Log.AdvancedTraceEvent("<comm.ADP.TraceException|ERR|ADV> Environment StackTrace = '{0}'", Environment.StackTrace);
3636
}
3737
}
3838

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ internal bool TryGetConnection(DbConnection owningConnection, TaskCompletionSour
163163
// connection creation failed on semaphore waiting or if max pool reached
164164
if (connectionPool.IsRunning)
165165
{
166-
SqlClientEventSource.Log.TraceEvent("<prov.DbConnectionFactory.GetConnection|RES|CPOOL> {0}#, GetConnection failed because a pool timeout occurred.", ObjectID);
166+
SqlClientEventSource.Log.TraceEvent("<prov.DbConnectionFactory.GetConnection|RES|CPOOL> {0}, GetConnection failed because a pool timeout occurred.", ObjectID);
167167
// If GetConnection failed while the pool is running, the pool timeout occurred.
168168
throw ADP.PooledOpenTimeout();
169169
}
@@ -181,7 +181,7 @@ internal bool TryGetConnection(DbConnection owningConnection, TaskCompletionSour
181181

182182
if (connection == null)
183183
{
184-
SqlClientEventSource.Log.TraceEvent("<prov.DbConnectionFactory.GetConnection|RES|CPOOL> {0}#, GetConnection failed because a pool timeout occurred and all retries were exhausted.", ObjectID);
184+
SqlClientEventSource.Log.TraceEvent("<prov.DbConnectionFactory.GetConnection|RES|CPOOL> {0}, GetConnection failed because a pool timeout occurred and all retries were exhausted.", ObjectID);
185185
// exhausted all retries or timed out - give up
186186
throw ADP.PooledOpenTimeout();
187187
}

0 commit comments

Comments
 (0)