diff --git a/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbBatchCommand.cs b/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbBatchCommand.cs index 9e17669d..a4aabf38 100644 --- a/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbBatchCommand.cs +++ b/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbBatchCommand.cs @@ -19,12 +19,11 @@ using System.Collections.Generic; using System.ComponentModel; using System.Data; -using System.Data.Common; -using System.Text; using System.Threading; using System.Threading.Tasks; using FirebirdSql.Data.Common; using FirebirdSql.Data.Logging; +using Microsoft.Extensions.Logging; namespace FirebirdSql.Data.FirebirdClient; @@ -33,7 +32,7 @@ public sealed class FbBatchCommand : IFbPreparedCommand, IDescriptorFiller, IDis , IAsyncDisposable #endif { - static readonly IFbLogger Log = FbLogManager.CreateLogger(nameof(FbBatchCommand)); + static readonly ILogger Log = FbLogManager.CreateLogger(); private const int DefaultBatchBufferSize = 16 * 1024 * 1024; diff --git a/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbCommand.cs b/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbCommand.cs index c5a2cdea..66abcb8f 100644 --- a/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbCommand.cs +++ b/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbCommand.cs @@ -25,12 +25,13 @@ using System.Threading.Tasks; using FirebirdSql.Data.Common; using FirebirdSql.Data.Logging; +using Microsoft.Extensions.Logging; namespace FirebirdSql.Data.FirebirdClient; public sealed class FbCommand : DbCommand, IFbPreparedCommand, IDescriptorFiller, ICloneable { - static readonly IFbLogger Log = FbLogManager.CreateLogger(nameof(FbCommand)); + static readonly ILogger Log = FbLogManager.CreateLogger(); #region Fields diff --git a/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnection.cs b/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnection.cs index 14d0c568..3effec5e 100644 --- a/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnection.cs +++ b/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnection.cs @@ -23,13 +23,14 @@ using System.Threading.Tasks; using FirebirdSql.Data.Common; using FirebirdSql.Data.Logging; +using Microsoft.Extensions.Logging; namespace FirebirdSql.Data.FirebirdClient; [DefaultEvent("InfoMessage")] public sealed class FbConnection : DbConnection, ICloneable { - static readonly IFbLogger Log = FbLogManager.CreateLogger(nameof(FbConnection)); + static readonly ILogger Log = FbLogManager.CreateLogger(); #region Static Pool Handling Methods diff --git a/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbTransaction.cs b/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbTransaction.cs index 4e5f0244..d6efb02c 100644 --- a/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbTransaction.cs +++ b/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbTransaction.cs @@ -22,12 +22,13 @@ using System.Threading.Tasks; using FirebirdSql.Data.Common; using FirebirdSql.Data.Logging; +using Microsoft.Extensions.Logging; namespace FirebirdSql.Data.FirebirdClient; public sealed class FbTransaction : DbTransaction { - static readonly IFbLogger Log = FbLogManager.CreateLogger(nameof(FbTransaction)); + static readonly ILogger Log = FbLogManager.CreateLogger(); internal const IsolationLevel DefaultIsolationLevel = IsolationLevel.ReadCommitted; diff --git a/src/FirebirdSql.Data.FirebirdClient/FirebirdSql.Data.FirebirdClient.csproj b/src/FirebirdSql.Data.FirebirdClient/FirebirdSql.Data.FirebirdClient.csproj index afc84988..7d38e917 100644 --- a/src/FirebirdSql.Data.FirebirdClient/FirebirdSql.Data.FirebirdClient.csproj +++ b/src/FirebirdSql.Data.FirebirdClient/FirebirdSql.Data.FirebirdClient.csproj @@ -61,6 +61,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/src/FirebirdSql.Data.FirebirdClient/Logging/ConsoleLoggingProvider.cs b/src/FirebirdSql.Data.FirebirdClient/Logging/ConsoleLoggingProvider.cs deleted file mode 100644 index e25eef26..00000000 --- a/src/FirebirdSql.Data.FirebirdClient/Logging/ConsoleLoggingProvider.cs +++ /dev/null @@ -1,74 +0,0 @@ -/* - * The contents of this file are subject to the Initial - * Developer's Public License Version 1.0 (the "License"); - * you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * https://github.com/FirebirdSQL/NETProvider/raw/master/license.txt. - * - * Software distributed under the License is distributed on - * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either - * express or implied. See the License for the specific - * language governing rights and limitations under the License. - * - * All Rights Reserved. - */ - -//$Authors = Jiri Cincura (jiri@cincura.net) - -using System; -using System.Text; - -namespace FirebirdSql.Data.Logging; - -[Obsolete("Use ConsoleLoggingProvider instead.")] -public class ConsoleLoggerProvider : ConsoleLoggingProvider -{ - public ConsoleLoggerProvider(FbLogLevel minimumLevel = FbLogLevel.Info) - : base(minimumLevel) - { } -} - -public class ConsoleLoggingProvider : IFbLoggingProvider -{ - readonly FbLogLevel _minimumLevel; - - public ConsoleLoggingProvider(FbLogLevel minimumLevel = FbLogLevel.Info) - { - _minimumLevel = minimumLevel; - } - - public IFbLogger CreateLogger(string name) => new ConsoleLogger(_minimumLevel); - - sealed class ConsoleLogger : IFbLogger - { - readonly FbLogLevel _minimumLevel; - - public ConsoleLogger(FbLogLevel minimumLevel) - { - _minimumLevel = minimumLevel; - } - - public bool IsEnabled(FbLogLevel level) - { - return level >= _minimumLevel; - } - - public void Log(FbLogLevel level, string msg, Exception exception = null) - { - if (!IsEnabled(level)) - return; - - var sb = new StringBuilder(); - sb.Append("["); - sb.Append(level.ToString().ToUpperInvariant()); - sb.Append("] "); - - sb.AppendLine(msg); - - if (exception != null) - sb.AppendLine(exception.ToString()); - - Console.Error.Write(sb.ToString()); - } - } -} diff --git a/src/FirebirdSql.Data.FirebirdClient/Logging/FbLogLevel.cs b/src/FirebirdSql.Data.FirebirdClient/Logging/FbLogLevel.cs deleted file mode 100644 index 3e48d930..00000000 --- a/src/FirebirdSql.Data.FirebirdClient/Logging/FbLogLevel.cs +++ /dev/null @@ -1,28 +0,0 @@ -/* - * The contents of this file are subject to the Initial - * Developer's Public License Version 1.0 (the "License"); - * you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * https://github.com/FirebirdSQL/NETProvider/raw/master/license.txt. - * - * Software distributed under the License is distributed on - * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either - * express or implied. See the License for the specific - * language governing rights and limitations under the License. - * - * All Rights Reserved. - */ - -//$Authors = Jiri Cincura (jiri@cincura.net) - -namespace FirebirdSql.Data.Logging; - -public enum FbLogLevel -{ - Trace = 1, - Debug = 2, - Info = 3, - Warn = 4, - Error = 5, - Fatal = 6, -} diff --git a/src/FirebirdSql.Data.FirebirdClient/Logging/FbLogManager.cs b/src/FirebirdSql.Data.FirebirdClient/Logging/FbLogManager.cs index 778e36d6..08c36efc 100644 --- a/src/FirebirdSql.Data.FirebirdClient/Logging/FbLogManager.cs +++ b/src/FirebirdSql.Data.FirebirdClient/Logging/FbLogManager.cs @@ -15,37 +15,26 @@ //$Authors = Jiri Cincura (jiri@cincura.net) -using System; +using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Logging; namespace FirebirdSql.Data.Logging; public static class FbLogManager { - public static IFbLoggingProvider Provider - { - get - { - _providerRetrieved = true; - return _provider; - } - set - { - if (_providerRetrieved) - throw new InvalidOperationException("The logging provider must be set before any action is taken"); + internal static ILoggerFactory LoggerFactory = NullLoggerFactory.Instance; + internal static bool IsParameterLoggingEnabled = false; - _provider = value ?? throw new ArgumentNullException(nameof(value)); - } + public static void UseLoggerFactory(ILoggerFactory loggerFactory) + { + LoggerFactory = loggerFactory; } - public static bool IsParameterLoggingEnabled { get; set; } - - static IFbLoggingProvider _provider; - static bool _providerRetrieved; - - static FbLogManager() + public static void EnableParameterLogging(bool enable = true) { - _provider = new NullLoggingProvider(); + IsParameterLoggingEnabled = enable; } - internal static IFbLogger CreateLogger(string name) => Provider.CreateLogger("FirebirdClient." + name); + internal static ILogger CreateLogger() => + LoggerFactory.CreateLogger(); } diff --git a/src/FirebirdSql.Data.FirebirdClient/Logging/IFbLogger.cs b/src/FirebirdSql.Data.FirebirdClient/Logging/IFbLogger.cs deleted file mode 100644 index f0f35052..00000000 --- a/src/FirebirdSql.Data.FirebirdClient/Logging/IFbLogger.cs +++ /dev/null @@ -1,43 +0,0 @@ -/* - * The contents of this file are subject to the Initial - * Developer's Public License Version 1.0 (the "License"); - * you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * https://github.com/FirebirdSQL/NETProvider/raw/master/license.txt. - * - * Software distributed under the License is distributed on - * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either - * express or implied. See the License for the specific - * language governing rights and limitations under the License. - * - * All Rights Reserved. - */ - -//$Authors = Jiri Cincura (jiri@cincura.net) - -using System; - -namespace FirebirdSql.Data.Logging; - -public interface IFbLogger -{ - bool IsEnabled(FbLogLevel level); - void Log(FbLogLevel level, string msg, Exception exception = null); -} - -public static class IFbLoggerExtensions -{ - public static void Trace(this IFbLogger logger, string msg) => logger.Log(FbLogLevel.Trace, msg); - public static void Debug(this IFbLogger logger, string msg) => logger.Log(FbLogLevel.Debug, msg); - public static void Info(this IFbLogger logger, string msg) => logger.Log(FbLogLevel.Info, msg); - public static void Warn(this IFbLogger logger, string msg) => logger.Log(FbLogLevel.Warn, msg); - public static void Error(this IFbLogger logger, string msg) => logger.Log(FbLogLevel.Error, msg); - public static void Fatal(this IFbLogger logger, string msg) => logger.Log(FbLogLevel.Fatal, msg); - - public static void Trace(this IFbLogger logger, string msg, Exception ex) => logger.Log(FbLogLevel.Trace, msg, ex); - public static void Debug(this IFbLogger logger, string msg, Exception ex) => logger.Log(FbLogLevel.Debug, msg, ex); - public static void Info(this IFbLogger logger, string msg, Exception ex) => logger.Log(FbLogLevel.Info, msg, ex); - public static void Warn(this IFbLogger logger, string msg, Exception ex) => logger.Log(FbLogLevel.Warn, msg, ex); - public static void Error(this IFbLogger logger, string msg, Exception ex) => logger.Log(FbLogLevel.Error, msg, ex); - public static void Fatal(this IFbLogger logger, string msg, Exception ex) => logger.Log(FbLogLevel.Fatal, msg, ex); -} diff --git a/src/FirebirdSql.Data.FirebirdClient/Logging/IFbLoggingProvider.cs b/src/FirebirdSql.Data.FirebirdClient/Logging/IFbLoggingProvider.cs deleted file mode 100644 index c152926a..00000000 --- a/src/FirebirdSql.Data.FirebirdClient/Logging/IFbLoggingProvider.cs +++ /dev/null @@ -1,23 +0,0 @@ -/* - * The contents of this file are subject to the Initial - * Developer's Public License Version 1.0 (the "License"); - * you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * https://github.com/FirebirdSQL/NETProvider/raw/master/license.txt. - * - * Software distributed under the License is distributed on - * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either - * express or implied. See the License for the specific - * language governing rights and limitations under the License. - * - * All Rights Reserved. - */ - -//$Authors = Jiri Cincura (jiri@cincura.net) - -namespace FirebirdSql.Data.Logging; - -public interface IFbLoggingProvider -{ - IFbLogger CreateLogger(string name); -} diff --git a/src/FirebirdSql.Data.FirebirdClient/Logging/LogMessages.cs b/src/FirebirdSql.Data.FirebirdClient/Logging/LogMessages.cs index e21b5227..de197d0a 100644 --- a/src/FirebirdSql.Data.FirebirdClient/Logging/LogMessages.cs +++ b/src/FirebirdSql.Data.FirebirdClient/Logging/LogMessages.cs @@ -16,274 +16,122 @@ //$Authors = Jiri Cincura (jiri@cincura.net) using System; -using System.Text; +using System.Collections.Generic; +using System.Data.Common; +using System.Linq; using FirebirdSql.Data.FirebirdClient; +using Microsoft.Extensions.Logging; namespace FirebirdSql.Data.Logging; static class LogMessages { - public static void CommandExecution(IFbLogger log, FbCommand command) + public static void CommandExecution(ILogger log, FbCommand command) { - if (!log.IsEnabled(FbLogLevel.Debug)) - return; - - var sb = new StringBuilder(); - sb.AppendLine("Command execution:"); - sb.AppendLine(command.CommandText); - if (FbLogManager.IsParameterLoggingEnabled) + if (!log.IsEnabled(LogLevel.Debug)) { - sb.AppendLine("Parameters:"); - if (!command.HasParameters) - { - sb.AppendLine(""); - } - else - { - foreach (FbParameter parameter in command.Parameters) - { - var name = parameter.ParameterName; - var type = parameter.FbDbType; - var value = !IsNullParameterValue(parameter.InternalValue) ? parameter.InternalValue : ""; - sb.AppendLine($"Name:{name}\tType:{type}\tUsed Value:{value}"); - } - } - } - log.Debug(sb.ToString()); - } - public static void CommandExecution(IFbLogger log, FbBatchCommand command) - { - if (!log.IsEnabled(FbLogLevel.Debug)) return; + } - var sb = new StringBuilder(); - sb.AppendLine("Command execution:"); - sb.AppendLine(command.CommandText); - if (FbLogManager.IsParameterLoggingEnabled) + if (!FbLogManager.IsParameterLoggingEnabled || !command.HasParameters) { - sb.AppendLine("Parameters:"); - if (command.HasParameters) - { - sb.AppendLine(""); - } - else - { - foreach (var batchParameter in command.BatchParameters) - { - foreach (FbParameter parameter in batchParameter) - { - var name = parameter.ParameterName; - var type = parameter.FbDbType; - var value = !IsNullParameterValue(parameter.InternalValue) ? parameter.InternalValue : ""; - sb.AppendLine($"Name:{name}\tType:{type}\tUsed Value:{value}"); - } - } - } + log.LogDebug("Command execution: {command}", command.CommandText); + return; } - log.Debug(sb.ToString()); + + var parameters = FbParameterCollectionToDictionary(command.Parameters); + log.LogDebug("Command execution: {command}, {parameters}", command.CommandText, parameters); } - public static void ConnectionOpening(IFbLogger log, FbConnection connection) + public static void CommandExecution(ILogger log, FbBatchCommand command) { - if (!log.IsEnabled(FbLogLevel.Debug)) + if (!log.IsEnabled(LogLevel.Debug)) + { return; + } - var sb = new StringBuilder(); - sb.AppendLine("Opening connection:"); - sb.AppendLine($"Connection String: {connection.ConnectionString}"); - log.Debug(sb.ToString()); - } - public static void ConnectionOpened(IFbLogger log, FbConnection connection) - { - if (!log.IsEnabled(FbLogLevel.Debug)) + if (!FbLogManager.IsParameterLoggingEnabled || !command.HasParameters) + { + log.LogDebug("Command execution: {command}", command.CommandText); return; + } - var sb = new StringBuilder(); - sb.AppendLine("Opened connection:"); - sb.AppendLine($"Connection String: {connection.ConnectionString}"); - log.Debug(sb.ToString()); + var parameters = command.BatchParameters.SelectMany(FbParameterCollectionToDictionary); + log.LogDebug("Command execution: {command}, {parameters}", command.CommandText, parameters); } - public static void ConnectionClosing(IFbLogger log, FbConnection connection) - { - if (!log.IsEnabled(FbLogLevel.Debug)) - return; - var sb = new StringBuilder(); - sb.AppendLine("Closing connection:"); - sb.AppendLine($"Connection String: {connection.ConnectionString}"); - log.Debug(sb.ToString()); - } - public static void ConnectionClosed(IFbLogger log, FbConnection connection) - { - if (!log.IsEnabled(FbLogLevel.Debug)) - return; + public static void ConnectionOpening(ILogger log, FbConnection connection) => + log.LogDebug("Opening connection: {connectionString}", connection.ConnectionString); - var sb = new StringBuilder(); - sb.AppendLine("Closed connection:"); - sb.AppendLine($"Connection String: {connection.ConnectionString}"); - log.Debug(sb.ToString()); - } + public static void ConnectionOpened(ILogger log, FbConnection connection) => + log.LogDebug("Opened connection: {connectionString}", connection.ConnectionString); - public static void TransactionBeginning(IFbLogger log, FbTransaction transaction) - { - if (!log.IsEnabled(FbLogLevel.Debug)) - return; + public static void ConnectionClosing(ILogger log, FbConnection connection) => + log.LogDebug("Closing connection: {connectionString}", connection.ConnectionString); - var sb = new StringBuilder(); - sb.AppendLine("Beginning transaction:"); - sb.AppendLine($"Isolation Level: {transaction.IsolationLevel}"); - log.Debug(sb.ToString()); - } - public static void TransactionBegan(IFbLogger log, FbTransaction transaction) - { - if (!log.IsEnabled(FbLogLevel.Debug)) - return; + public static void ConnectionClosed(ILogger log, FbConnection connection) => + log.LogDebug("Closed connection: {connectionString}", connection.ConnectionString); - var sb = new StringBuilder(); - sb.AppendLine("Began transaction:"); - sb.AppendLine($"Isolation Level: {transaction.IsolationLevel}"); - log.Debug(sb.ToString()); - } - public static void TransactionCommitting(IFbLogger log, FbTransaction transaction) - { - if (!log.IsEnabled(FbLogLevel.Debug)) - return; + public static void TransactionBeginning(ILogger log, FbTransaction transaction) => + // TODO: Transaction Id? + log.LogDebug("Beginning transaction: {isolationLevel}", transaction.IsolationLevel); - var sb = new StringBuilder(); - sb.AppendLine("Committing transaction:"); - sb.AppendLine($"Isolation Level: {transaction.IsolationLevel}"); - log.Debug(sb.ToString()); - } - public static void TransactionCommitted(IFbLogger log, FbTransaction transaction) - { - if (!log.IsEnabled(FbLogLevel.Debug)) - return; + public static void TransactionBegan(ILogger log, FbTransaction transaction) => + log.LogDebug("Began transaction: {isolationLevel}", transaction.IsolationLevel); - var sb = new StringBuilder(); - sb.AppendLine("Committed transaction:"); - sb.AppendLine($"Isolation Level: {transaction.IsolationLevel}"); - log.Debug(sb.ToString()); - } - public static void TransactionRollingBack(IFbLogger log, FbTransaction transaction) - { - if (!log.IsEnabled(FbLogLevel.Debug)) - return; + public static void TransactionCommitting(ILogger log, FbTransaction transaction) => + log.LogDebug("Committing transaction: {isolationLevel}", transaction.IsolationLevel); - var sb = new StringBuilder(); - sb.AppendLine("Rolling back transaction:"); - sb.AppendLine($"Isolation Level: {transaction.IsolationLevel}"); - log.Debug(sb.ToString()); - } - public static void TransactionRolledBack(IFbLogger log, FbTransaction transaction) - { - if (!log.IsEnabled(FbLogLevel.Debug)) - return; + public static void TransactionCommitted(ILogger log, FbTransaction transaction) => + log.LogDebug("Committed transaction: {isolationLevel}", transaction.IsolationLevel); - var sb = new StringBuilder(); - sb.AppendLine("Rolled back transaction:"); - sb.AppendLine($"Isolation Level: {transaction.IsolationLevel}"); - log.Debug(sb.ToString()); - } - public static void TransactionSaving(IFbLogger log, FbTransaction transaction) - { - if (!log.IsEnabled(FbLogLevel.Debug)) - return; + public static void TransactionRollingBack(ILogger log, FbTransaction transaction) => + log.LogDebug("Rolling back transaction: {isolationLevel}", transaction.IsolationLevel); - var sb = new StringBuilder(); - sb.AppendLine("Creating savepoint:"); - sb.AppendLine($"Isolation Level: {transaction.IsolationLevel}"); - log.Debug(sb.ToString()); - } - public static void TransactionSaved(IFbLogger log, FbTransaction transaction) - { - if (!log.IsEnabled(FbLogLevel.Debug)) - return; + public static void TransactionRolledBack(ILogger log, FbTransaction transaction) => + log.LogDebug("Rolled back transaction: {isolationLevel}", transaction.IsolationLevel); - var sb = new StringBuilder(); - sb.AppendLine("Created savepoint:"); - sb.AppendLine($"Isolation Level: {transaction.IsolationLevel}"); - log.Debug(sb.ToString()); - } - public static void TransactionReleasingSavepoint(IFbLogger log, FbTransaction transaction) - { - if (!log.IsEnabled(FbLogLevel.Debug)) - return; + public static void TransactionSaving(ILogger log, FbTransaction transaction) => + log.LogDebug("Creating savepoint: {isolationLevel}", transaction.IsolationLevel); - var sb = new StringBuilder(); - sb.AppendLine("Releasing savepoint:"); - sb.AppendLine($"Isolation Level: {transaction.IsolationLevel}"); - log.Debug(sb.ToString()); - } - public static void TransactionReleasedSavepoint(IFbLogger log, FbTransaction transaction) - { - if (!log.IsEnabled(FbLogLevel.Debug)) - return; + public static void TransactionSaved(ILogger log, FbTransaction transaction) => + log.LogDebug("Created savepoint: {isolationLevel}", transaction.IsolationLevel); - var sb = new StringBuilder(); - sb.AppendLine("Released savepoint:"); - sb.AppendLine($"Isolation Level: {transaction.IsolationLevel}"); - log.Debug(sb.ToString()); - } - public static void TransactionRollingBackSavepoint(IFbLogger log, FbTransaction transaction) - { - if (!log.IsEnabled(FbLogLevel.Debug)) - return; + public static void TransactionReleasingSavepoint(ILogger log, FbTransaction transaction) => + log.LogDebug("Releasing savepoint: {isolationLevel}", transaction.IsolationLevel); - var sb = new StringBuilder(); - sb.AppendLine("Rolling back savepoint:"); - sb.AppendLine($"Isolation Level: {transaction.IsolationLevel}"); - log.Debug(sb.ToString()); - } - public static void TransactionRolledBackSavepoint(IFbLogger log, FbTransaction transaction) - { - if (!log.IsEnabled(FbLogLevel.Debug)) - return; + public static void TransactionReleasedSavepoint(ILogger log, FbTransaction transaction) => + log.LogDebug("Released savepoint: {isolationLevel}", transaction.IsolationLevel); - var sb = new StringBuilder(); - sb.AppendLine("Rolled back savepoint:"); - sb.AppendLine($"Isolation Level: {transaction.IsolationLevel}"); - log.Debug(sb.ToString()); - } - public static void TransactionCommittingRetaining(IFbLogger log, FbTransaction transaction) - { - if (!log.IsEnabled(FbLogLevel.Debug)) - return; + public static void TransactionRollingBackSavepoint(ILogger log, FbTransaction transaction) => + log.LogDebug("Rolling back savepoint: {isolationLevel}", transaction.IsolationLevel); - var sb = new StringBuilder(); - sb.AppendLine("Committing (retaining) transaction:"); - sb.AppendLine($"Isolation Level: {transaction.IsolationLevel}"); - log.Debug(sb.ToString()); - } - public static void TransactionCommittedRetaining(IFbLogger log, FbTransaction transaction) - { - if (!log.IsEnabled(FbLogLevel.Debug)) - return; + public static void TransactionRolledBackSavepoint(ILogger log, FbTransaction transaction) => + log.LogDebug("Rolled back savepoint: {isolationLevel}", transaction.IsolationLevel); - var sb = new StringBuilder(); - sb.AppendLine("Committed (retaining) transaction:"); - sb.AppendLine($"Isolation Level: {transaction.IsolationLevel}"); - log.Debug(sb.ToString()); - } - public static void TransactionRollingBackRetaining(IFbLogger log, FbTransaction transaction) - { - if (!log.IsEnabled(FbLogLevel.Debug)) - return; + public static void TransactionCommittingRetaining(ILogger log, FbTransaction transaction) => + log.LogDebug("Committing (retaining) transaction: {isolationLevel}", transaction.IsolationLevel); - var sb = new StringBuilder(); - sb.AppendLine("Rolling back (retaining) transaction:"); - sb.AppendLine($"Isolation Level: {transaction.IsolationLevel}"); - log.Debug(sb.ToString()); - } - public static void TransactionRolledBackRetaining(IFbLogger log, FbTransaction transaction) - { - if (!log.IsEnabled(FbLogLevel.Debug)) - return; + public static void TransactionCommittedRetaining(ILogger log, FbTransaction transaction) => + log.LogDebug("Committed (retaining) transaction: {isolationLevel}", transaction.IsolationLevel); - var sb = new StringBuilder(); - sb.AppendLine("Rolled back (retaining) transaction:"); - sb.AppendLine($"Isolation Level: {transaction.IsolationLevel}"); - log.Debug(sb.ToString()); - } + public static void TransactionRollingBackRetaining(ILogger log, FbTransaction transaction) => + log.LogDebug("Rolling back (retaining) transaction: {isolationLevel}", transaction.IsolationLevel); + + public static void TransactionRolledBackRetaining(ILogger log, FbTransaction transaction) => + log.LogDebug("Rolled back (retaining) transaction: {isolationLevel}", transaction.IsolationLevel); + + private static object NormalizeDbNull(object value) => + value == DBNull.Value || value == null + ? null + : value; - static bool IsNullParameterValue(object value) => value == DBNull.Value || value == null; + private static Dictionary FbParameterCollectionToDictionary(FbParameterCollection parameters) => + parameters + .Cast() + .ToList() + .ToDictionary( + p => p.ParameterName, + p => NormalizeDbNull(p.Value) + ); } diff --git a/src/FirebirdSql.Data.FirebirdClient/Logging/NullLoggingProvider.cs b/src/FirebirdSql.Data.FirebirdClient/Logging/NullLoggingProvider.cs deleted file mode 100644 index bb2a5f16..00000000 --- a/src/FirebirdSql.Data.FirebirdClient/Logging/NullLoggingProvider.cs +++ /dev/null @@ -1,36 +0,0 @@ -/* - * The contents of this file are subject to the Initial - * Developer's Public License Version 1.0 (the "License"); - * you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * https://github.com/FirebirdSQL/NETProvider/raw/master/license.txt. - * - * Software distributed under the License is distributed on - * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either - * express or implied. See the License for the specific - * language governing rights and limitations under the License. - * - * All Rights Reserved. - */ - -//$Authors = Jiri Cincura (jiri@cincura.net) - -using System; - -namespace FirebirdSql.Data.Logging; - -sealed class NullLoggingProvider : IFbLoggingProvider -{ - public IFbLogger CreateLogger(string name) => NullLogger.Instance; - - sealed class NullLogger : IFbLogger - { - internal static NullLogger Instance = new NullLogger(); - - NullLogger() { } - - public bool IsEnabled(FbLogLevel level) => false; - - public void Log(FbLogLevel level, string msg, Exception exception = null) { } - } -}