@@ -386,11 +386,16 @@ public static async Task<ServerProperties> GetServerTelemetryProperties(SqlConne
386
386
/// <param name="cmd">The SqlCommand being executed</param>
387
387
/// <param name="logger">The logger</param>
388
388
/// <param name="cancellationToken">The cancellation token to pass to the call</param>
389
+ /// <param name="logCommand">Defaults to false and when set logs the command being executed</param>
389
390
/// <returns>The result of the call</returns>
390
- public static async Task < object > ExecuteScalarAsyncWithLogging ( this SqlCommand cmd , ILogger logger , CancellationToken cancellationToken )
391
+ public static async Task < object > ExecuteScalarAsyncWithLogging ( this SqlCommand cmd , ILogger logger , CancellationToken cancellationToken , bool logCommand = false )
391
392
{
392
393
try
393
394
{
395
+ if ( logCommand )
396
+ {
397
+ logger . LogDebug ( $ "Executing query={ cmd . CommandText } ") ;
398
+ }
394
399
return await cmd . ExecuteScalarAsync ( cancellationToken ) ;
395
400
}
396
401
catch ( Exception e )
@@ -406,11 +411,16 @@ public static async Task<object> ExecuteScalarAsyncWithLogging(this SqlCommand c
406
411
/// <param name="cmd">The SqlCommand being executed</param>
407
412
/// <param name="logger">The logger</param>
408
413
/// <param name="cancellationToken">The cancellation token to pass to the call</param>
414
+ /// <param name="logCommand">Defaults to false and when set logs the command being executed</param>
409
415
/// <returns>The result of the call</returns>
410
- public static async Task < int > ExecuteNonQueryAsyncWithLogging ( this SqlCommand cmd , ILogger logger , CancellationToken cancellationToken )
416
+ public static async Task < int > ExecuteNonQueryAsyncWithLogging ( this SqlCommand cmd , ILogger logger , CancellationToken cancellationToken , bool logCommand = false )
411
417
{
412
418
try
413
419
{
420
+ if ( logCommand )
421
+ {
422
+ logger . LogDebug ( $ "Executing query={ cmd . CommandText } ") ;
423
+ }
414
424
return await cmd . ExecuteNonQueryAsync ( cancellationToken ) ;
415
425
}
416
426
catch ( Exception e )
@@ -426,11 +436,16 @@ public static async Task<int> ExecuteNonQueryAsyncWithLogging(this SqlCommand cm
426
436
/// <param name="cmd">The SqlCommand being executed</param>
427
437
/// <param name="logger">The logger</param>
428
438
/// <param name="cancellationToken">The cancellation token to pass to the call</param>
439
+ /// <param name="logCommand">Defaults to false and when set logs the command being executed</param>
429
440
/// <returns>The result of the call</returns>
430
- public static async Task < SqlDataReader > ExecuteReaderAsyncWithLogging ( this SqlCommand cmd , ILogger logger , CancellationToken cancellationToken )
441
+ public static async Task < SqlDataReader > ExecuteReaderAsyncWithLogging ( this SqlCommand cmd , ILogger logger , CancellationToken cancellationToken , bool logCommand = false )
431
442
{
432
443
try
433
444
{
445
+ if ( logCommand )
446
+ {
447
+ logger . LogDebug ( $ "Executing query={ cmd . CommandText } ") ;
448
+ }
434
449
return await cmd . ExecuteReaderAsync ( cancellationToken ) ;
435
450
}
436
451
catch ( Exception e )
0 commit comments