Skip to content

Commit 50b318d

Browse files
committed
Small cleanup around logging.
1 parent 2596baf commit 50b318d

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

src/FirebirdSql.Data.FirebirdClient/Logging/FbLogManager.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,15 @@ namespace FirebirdSql.Data.Logging;
2222

2323
public static class FbLogManager
2424
{
25-
internal static ILoggerFactory LoggerFactory = NullLoggerFactory.Instance;
26-
internal static bool IsParameterLoggingEnabled = false;
25+
public static bool IsParameterLoggingEnabled { get; private set; } = false;
2726

28-
public static void UseLoggerFactory(ILoggerFactory loggerFactory)
29-
{
27+
private static ILoggerFactory LoggerFactory = NullLoggerFactory.Instance;
28+
29+
public static void UseLoggerFactory(ILoggerFactory loggerFactory) =>
3030
LoggerFactory = loggerFactory;
31-
}
3231

33-
public static void EnableParameterLogging(bool enable = true)
34-
{
32+
public static void EnableParameterLogging(bool enable = true) =>
3533
IsParameterLoggingEnabled = enable;
36-
}
3734

3835
internal static ILogger<T> CreateLogger<T>() =>
3936
LoggerFactory.CreateLogger<T>();

src/FirebirdSql.Data.FirebirdClient/Logging/LogMessages.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ public static void CommandExecution(ILogger log, FbCommand command)
3333
return;
3434
}
3535

36-
if (!FbLogManager.IsParameterLoggingEnabled || !command.HasParameters)
36+
if (FbLogManager.IsParameterLoggingEnabled && command.HasParameters)
37+
{
38+
var parameters = FbParameterCollectionToDictionary(command.Parameters);
39+
log.LogDebug("Command execution: {command}, {parameters}", command.CommandText, parameters);
40+
}
41+
else
3742
{
3843
log.LogDebug("Command execution: {command}", command.CommandText);
39-
return;
4044
}
41-
42-
var parameters = FbParameterCollectionToDictionary(command.Parameters);
43-
log.LogDebug("Command execution: {command}, {parameters}", command.CommandText, parameters);
4445
}
4546

4647
public static void CommandExecution(ILogger log, FbBatchCommand command)
@@ -50,14 +51,15 @@ public static void CommandExecution(ILogger log, FbBatchCommand command)
5051
return;
5152
}
5253

53-
if (!FbLogManager.IsParameterLoggingEnabled || !command.HasParameters)
54+
if (FbLogManager.IsParameterLoggingEnabled && command.HasParameters)
55+
{
56+
var parameters = command.BatchParameters.SelectMany(FbParameterCollectionToDictionary);
57+
log.LogDebug("Command execution: {command}, {parameters}", command.CommandText, parameters);
58+
}
59+
else
5460
{
5561
log.LogDebug("Command execution: {command}", command.CommandText);
56-
return;
5762
}
58-
59-
var parameters = command.BatchParameters.SelectMany(FbParameterCollectionToDictionary);
60-
log.LogDebug("Command execution: {command}, {parameters}", command.CommandText, parameters);
6163
}
6264

6365
public static void ConnectionOpening(ILogger log, FbConnection connection) =>
@@ -129,7 +131,6 @@ private static object NormalizeDbNull(object value) =>
129131
private static Dictionary<string, object> FbParameterCollectionToDictionary(FbParameterCollection parameters) =>
130132
parameters
131133
.Cast<DbParameter>()
132-
.ToList()
133134
.ToDictionary(
134135
p => p.ParameterName,
135136
p => NormalizeDbNull(p.Value)

0 commit comments

Comments
 (0)