@@ -99,9 +99,7 @@ public SqlAsyncCollector(IConfiguration configuration, SqlAttribute attribute, I
9999 TelemetryInstance . TrackCreate ( CreateType . SqlAsyncCollector ) ;
100100 using ( SqlConnection connection = BuildConnection ( attribute . ConnectionStringSetting , configuration ) )
101101 {
102- this . _logger . LogDebugWithThreadId ( "BEGIN OpenSqlAsyncCollectorVerifyDatabaseSupportedConnection" ) ;
103102 connection . OpenAsyncWithSqlErrorHandling ( CancellationToken . None ) . Wait ( ) ;
104- this . _logger . LogDebugWithThreadId ( "END OpenSqlAsyncCollectorVerifyDatabaseSupportedConnection" ) ;
105103 VerifyDatabaseSupported ( connection , logger , CancellationToken . None ) . Wait ( ) ;
106104 }
107105 }
@@ -172,13 +170,10 @@ public async Task FlushAsync(CancellationToken cancellationToken = default)
172170 /// <param name="configuration"> Used to build up the connection </param>
173171 private async Task UpsertRowsAsync ( IList < T > rows , SqlAttribute attribute , IConfiguration configuration )
174172 {
175- this . _logger . LogDebugWithThreadId ( "BEGIN UpsertRowsAsync" ) ;
176173 var upsertRowsAsyncSw = Stopwatch . StartNew ( ) ;
177174 using ( SqlConnection connection = BuildConnection ( attribute . ConnectionStringSetting , configuration ) )
178175 {
179- this . _logger . LogDebugWithThreadId ( "BEGIN OpenUpsertRowsAsyncConnection" ) ;
180176 await connection . OpenAsync ( ) ;
181- this . _logger . LogDebugWithThreadId ( "END OpenUpsertRowsAsyncConnection" ) ;
182177 this . _serverProperties = await GetServerTelemetryProperties ( connection , this . _logger , CancellationToken . None ) ;
183178 Dictionary < TelemetryPropertyName , string > props = connection . AsConnectionProps ( this . _serverProperties ) ;
184179
@@ -196,7 +191,7 @@ private async Task UpsertRowsAsync(IList<T> rows, SqlAttribute attribute, IConfi
196191 {
197192 if ( int . TryParse ( timeoutEnvVar , NumberStyles . Integer , CultureInfo . InvariantCulture , out timeout ) )
198193 {
199- this . _logger . LogDebugWithThreadId ( $ "Overriding default table info cache timeout with new value { timeout } ") ;
194+ this . _logger . LogDebug ( $ "Overriding default table info cache timeout with new value { timeout } ") ;
200195 }
201196 else
202197 {
@@ -253,7 +248,6 @@ private async Task UpsertRowsAsync(IList<T> rows, SqlAttribute attribute, IConfi
253248 string mergeOrInsertQuery = tableInfo . QueryType == QueryType . Insert ? TableInformation . GetInsertQuery ( table , bracketedColumnNamesFromItem ) :
254249 TableInformation . GetMergeQuery ( tableInfo . PrimaryKeys , table , bracketedColumnNamesFromItem ) ;
255250
256- this . _logger . LogDebugWithThreadId ( "BEGIN UpsertRowsTransaction" ) ;
257251 var transactionSw = Stopwatch . StartNew ( ) ;
258252 int batchSize = 1000 ;
259253 SqlTransaction transaction = connection . BeginTransaction ( ) ;
@@ -270,9 +264,8 @@ private async Task UpsertRowsAsync(IList<T> rows, SqlAttribute attribute, IConfi
270264 batchCount ++ ;
271265 GenerateDataQueryForMerge ( tableInfo , batch , out string newDataQuery , out string rowData ) ;
272266 command . CommandText = $ "{ newDataQuery } { mergeOrInsertQuery } ;";
273- this . _logger . LogDebugWithThreadId ( $ "UpsertRowsTransactionBatch - Query={ command . CommandText } ") ;
274267 par . Value = rowData ;
275- await command . ExecuteNonQueryAsync ( ) ;
268+ await command . ExecuteNonQueryAsyncWithLogging ( this . _logger , CancellationToken . None ) ;
276269 }
277270 transaction . Commit ( ) ;
278271 transactionSw . Stop ( ) ;
@@ -286,8 +279,6 @@ private async Task UpsertRowsAsync(IList<T> rows, SqlAttribute attribute, IConfi
286279 { TelemetryMeasureName . NumRows , rows . Count }
287280 } ;
288281 TelemetryInstance . TrackEvent ( TelemetryEventName . Upsert , props , measures ) ;
289- this . _logger . LogDebugWithThreadId ( $ "END UpsertRowsTransaction Duration={ transactionSw . ElapsedMilliseconds } ms Upserted { rows . Count } row(s) into database: { connection . Database } and table: { fullTableName } .") ;
290- this . _logger . LogDebugWithThreadId ( $ "END UpsertRowsAsync Duration={ upsertRowsAsyncSw . ElapsedMilliseconds } ms") ;
291282 }
292283 catch ( Exception ex )
293284 {
@@ -562,7 +553,6 @@ WHEN NOT MATCHED THEN
562553 public static async Task < TableInformation > RetrieveTableInformationAsync ( SqlConnection sqlConnection , string fullName , ILogger logger , IEnumerable < string > objectColumnNames , ServerProperties serverProperties )
563554 {
564555 Dictionary < TelemetryPropertyName , string > sqlConnProps = sqlConnection . AsConnectionProps ( serverProperties ) ;
565- logger . LogDebugWithThreadId ( "BEGIN RetrieveTableInformationAsync" ) ;
566556 var table = new SqlObject ( fullName ) ;
567557
568558 var tableInfoSw = Stopwatch . StartNew ( ) ;
@@ -573,9 +563,8 @@ public static async Task<TableInformation> RetrieveTableInformationAsync(SqlConn
573563 try
574564 {
575565 string getColumnDefinitionsQuery = GetColumnDefinitionsQuery ( table ) ;
576- logger . LogDebugWithThreadId ( $ "BEGIN GetColumnDefinitions Query=\" { getColumnDefinitionsQuery } \" ") ;
577566 var cmdColDef = new SqlCommand ( getColumnDefinitionsQuery , sqlConnection ) ;
578- using ( SqlDataReader rdr = await cmdColDef . ExecuteReaderAsync ( ) )
567+ using ( SqlDataReader rdr = await cmdColDef . ExecuteReaderAsyncWithLogging ( logger , CancellationToken . None ) )
579568 {
580569 while ( await rdr . ReadAsync ( ) )
581570 {
@@ -584,7 +573,6 @@ public static async Task<TableInformation> RetrieveTableInformationAsync(SqlConn
584573 }
585574 columnDefinitionsSw . Stop ( ) ;
586575 TelemetryInstance . TrackDuration ( TelemetryEventName . GetColumnDefinitions , columnDefinitionsSw . ElapsedMilliseconds , sqlConnProps ) ;
587- logger . LogDebugWithThreadId ( $ "END GetColumnDefinitions Duration={ columnDefinitionsSw . ElapsedMilliseconds } ms") ;
588576 }
589577
590578 }
@@ -610,9 +598,8 @@ public static async Task<TableInformation> RetrieveTableInformationAsync(SqlConn
610598 try
611599 {
612600 string getPrimaryKeysQuery = GetPrimaryKeysQuery ( table ) ;
613- logger . LogDebugWithThreadId ( $ "BEGIN GetPrimaryKeys Query=\" { getPrimaryKeysQuery } \" ") ;
614601 var cmd = new SqlCommand ( getPrimaryKeysQuery , sqlConnection ) ;
615- using ( SqlDataReader rdr = await cmd . ExecuteReaderAsync ( ) )
602+ using ( SqlDataReader rdr = await cmd . ExecuteReaderAsyncWithLogging ( logger , CancellationToken . None ) )
616603 {
617604 while ( await rdr . ReadAsync ( ) )
618605 {
@@ -621,7 +608,6 @@ public static async Task<TableInformation> RetrieveTableInformationAsync(SqlConn
621608 }
622609 primaryKeysSw . Stop ( ) ;
623610 TelemetryInstance . TrackDuration ( TelemetryEventName . GetPrimaryKeys , primaryKeysSw . ElapsedMilliseconds , sqlConnProps ) ;
624- logger . LogDebugWithThreadId ( $ "END GetPrimaryKeys Duration={ primaryKeysSw . ElapsedMilliseconds } ms") ;
625611 }
626612 }
627613 catch ( Exception ex )
@@ -670,7 +656,7 @@ public static async Task<TableInformation> RetrieveTableInformationAsync(SqlConn
670656 sqlConnProps . Add ( TelemetryPropertyName . QueryType , queryType . ToString ( ) ) ;
671657 sqlConnProps . Add ( TelemetryPropertyName . HasIdentityColumn , hasIdentityColumnPrimaryKeys . ToString ( ) ) ;
672658 TelemetryInstance . TrackDuration ( TelemetryEventName . GetTableInfo , tableInfoSw . ElapsedMilliseconds , sqlConnProps , durations ) ;
673- logger . LogDebugWithThreadId ( $ "END RetrieveTableInformationAsync Duration= { tableInfoSw . ElapsedMilliseconds } ms DB and Table: { sqlConnection . Database } .{ fullName } . Primary keys: [{ string . Join ( "," , primaryKeys . Select ( pk => pk . Name ) ) } ]. SQL Column and Definitions: [{ string . Join ( "," , columnDefinitionsFromSQL ) } ] Object columns: [{ string . Join ( "," , objectColumnNames ) } ]") ;
659+ logger . LogDebug ( $ "RetrieveTableInformationAsync DB and Table: { sqlConnection . Database } .{ fullName } . Primary keys: [{ string . Join ( "," , primaryKeys . Select ( pk => pk . Name ) ) } ].\n SQL Column and Definitions: [{ string . Join ( "," , columnDefinitionsFromSQL ) } ]\n Object columns: [{ string . Join ( "," , objectColumnNames ) } ]") ;
674660 return new TableInformation ( primaryKeys , primaryKeyProperties , columnDefinitionsFromSQL , queryType , hasIdentityColumnPrimaryKeys ) ;
675661 }
676662 }
0 commit comments