using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
namespace Npgsql;
///
/// Configures Npgsql logging
///
public class NpgsqlLoggingConfiguration
{
internal static readonly NpgsqlLoggingConfiguration NullConfiguration
= new(NullLoggerFactory.Instance, isParameterLoggingEnabled: false);
internal static ILoggerFactory GlobalLoggerFactory = NullLoggerFactory.Instance;
internal static bool GlobalIsParameterLoggingEnabled;
internal NpgsqlLoggingConfiguration(ILoggerFactory loggerFactory, bool isParameterLoggingEnabled)
{
ConnectionLogger = loggerFactory.CreateLogger("Npgsql.Connection");
CommandLogger = loggerFactory.CreateLogger("Npgsql.Command");
TransactionLogger = loggerFactory.CreateLogger("Npgsql.Transaction");
CopyLogger = loggerFactory.CreateLogger("Npgsql.Copy");
ReplicationLogger = loggerFactory.CreateLogger("Npgsql.Replication");
ExceptionLogger = loggerFactory.CreateLogger("Npgsql.Exception");
IsParameterLoggingEnabled = isParameterLoggingEnabled;
}
internal ILogger ConnectionLogger { get; }
internal ILogger CommandLogger { get; }
internal ILogger TransactionLogger { get; }
internal ILogger CopyLogger { get; }
internal ILogger ReplicationLogger { get; }
internal ILogger ExceptionLogger { get; }
///
/// Determines whether parameter contents will be logged alongside SQL statements - this may reveal sensitive information.
/// Defaults to false.
///
internal bool IsParameterLoggingEnabled { get; }
///
///
/// Globally initializes Npgsql logging to use the provided .
/// Must be called before any Npgsql APIs are used.
///
///
/// This is a legacy-only, backwards compatibility API. New applications should set the logger factory on
/// and use the resulting instead.
///
///
/// The logging factory to use when logging from Npgsql.
///
/// Determines whether parameter contents will be logged alongside SQL statements - this may reveal sensitive information.
/// Defaults to .
///
public static void InitializeLogging(ILoggerFactory loggerFactory, bool parameterLoggingEnabled = false)
=> (GlobalLoggerFactory, GlobalIsParameterLoggingEnabled) = (loggerFactory, parameterLoggingEnabled);
}