Skip to content

Commit c116c21

Browse files
committed
The Stopwatch is now only allocated when SqlLoggingEnabled is true, and the logging check reuses the null-check on stopwatch instead of re-reading the flag.
1 parent a5c556d commit c116c21

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/LocalDb/SqlExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public static async Task ExecuteCommandAsync(this SqlConnection connection, stri
66

77
try
88
{
9-
var stopwatch = Stopwatch.StartNew();
9+
var stopwatch = LocalDbLogging.SqlLoggingEnabled ? Stopwatch.StartNew() : null;
1010

1111
#if NET5_0_OR_GREATER
1212
await using (var command = connection.CreateCommand())
@@ -18,7 +18,7 @@ public static async Task ExecuteCommandAsync(this SqlConnection connection, stri
1818
await command.ExecuteNonQueryAsync();
1919
}
2020

21-
if (LocalDbLogging.SqlLoggingEnabled)
21+
if (stopwatch != null)
2222
{
2323
LocalDbLogging.Log($"""
2424
Executed SQL ({stopwatch.ElapsedMilliseconds}.ms):

0 commit comments

Comments
 (0)