Class DbConnectionLoggerExtensions
- Namespace
- Wolfgang.Extensions.Logging.Data
- Assembly
- Wolfgang.Extensions.Logging.Data.dll
Extension methods on ILogger for logging DbConnection instances.
public static class DbConnectionLoggerExtensions
- Inheritance
-
DbConnectionLoggerExtensions
- Inherited Members
Remarks
The ConnectionString is parsed via
DbConnectionStringBuilder and the Password and Pwd keys are
removed before logging so credentials are never written to the log. Key matching is
case-insensitive per the DbConnectionStringBuilder contract, so
password, PASSWORD, etc. are all redacted. All other keys, including the
user name (User ID, UID, etc.), are preserved.
Methods
LogDbConnection(ILogger, DbConnection)
Logs a single structured entry describing the connection at
LogLevel.Information.
public static void LogDbConnection(this ILogger logger, DbConnection connection)
Parameters
loggerILoggerThe logger to write to.
connectionDbConnectionThe connection to log.
Examples
using var connection = new SqlConnection(connectionString);
await connection.OpenAsync();
logger.LogDbConnection(connection);
Exceptions
- ArgumentNullException
Thrown when
loggerorconnectionis null.
LogDbConnection(ILogger, DbConnection, LogLevel)
Logs a single structured entry describing the connection at the
specified level.
public static void LogDbConnection(this ILogger logger, DbConnection connection, LogLevel level)
Parameters
loggerILoggerThe logger to write to.
connectionDbConnectionThe connection to log.
levelLogLevelThe log level to write the entry at.
Examples
using var connection = new SqlConnection(connectionString);
await connection.OpenAsync();
logger.LogDbConnection(connection, LogLevel.Debug);
Exceptions
- ArgumentNullException
Thrown when
loggerorconnectionis null.