Wolfgang.Extensions.Logging.Data.EntityFramework6 0.2.1

Prefix Reserved
dotnet add package Wolfgang.Extensions.Logging.Data.EntityFramework6 --version 0.2.1
                    
NuGet\Install-Package Wolfgang.Extensions.Logging.Data.EntityFramework6 -Version 0.2.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Wolfgang.Extensions.Logging.Data.EntityFramework6" Version="0.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Wolfgang.Extensions.Logging.Data.EntityFramework6" Version="0.2.1" />
                    
Directory.Packages.props
<PackageReference Include="Wolfgang.Extensions.Logging.Data.EntityFramework6" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Wolfgang.Extensions.Logging.Data.EntityFramework6 --version 0.2.1
                    
#r "nuget: Wolfgang.Extensions.Logging.Data.EntityFramework6, 0.2.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Wolfgang.Extensions.Logging.Data.EntityFramework6@0.2.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Wolfgang.Extensions.Logging.Data.EntityFramework6&version=0.2.1
                    
Install as a Cake Addin
#tool nuget:?package=Wolfgang.Extensions.Logging.Data.EntityFramework6&version=0.2.1
                    
Install as a Cake Tool

Wolfgang.Extensions.Logging.Data

Extension methods on ILogger for logging DbConnection, DbCommand, and other System.Data types — with credential redaction baked in so passwords never reach the log.

NuGet NuGet downloads PR build Release License: MIT .NET GitHub OpenSSF Scorecard


📦 Installation

dotnet add package Wolfgang.Extensions.Logging.Data

NuGet Package: Wolfgang.Extensions.Logging.Data


📄 License

This project is licensed under the MIT License. See the LICENSE file for details.


📚 Documentation


🚀 Quick Start

using System.Data.SqlClient;
using Microsoft.Extensions.Logging;
using Wolfgang.Extensions.Logging.Data;

ILogger logger = /* … your DI-resolved ILogger … */;

using var connection = new SqlConnection(connectionString);
await connection.OpenAsync();

// Logs one structured entry: ConnectionType, Database, DataSource,
// ServerVersion, State, ConnectionTimeout, ConnectionString — with
// Password / Pwd keys removed before the entry is written.
logger.LogDbConnection(connection);

Want it at a different level than the default Information? Pass one:

logger.LogDbConnection(connection, LogLevel.Debug);

✨ Features

Feature Method
Log a DbConnection at LogLevel.Information (default) ILogger.LogDbConnection(DbConnection)
Log a DbConnection at a specific LogLevel ILogger.LogDbConnection(DbConnection, LogLevel)
Credential redaction — Password / Pwd keys are stripped from the connection string before it's emitted (built-in to every overload)
Structured logging — emits as templated log entry with named properties ({ConnectionType}, {Database}, {DataSource}, etc.) for structured-log sinks like Serilog, Application Insights, or Elastic (built-in)
IsEnabled(level) short-circuit — work is skipped if the log level isn't enabled, so the redaction / DbConnectionStringBuilder parse only runs when the entry will actually be written (built-in)
Null-safe — throws ArgumentNullException (not NullReferenceException) when logger or connection is null (every overload)

DbCommand logging is also available via ILogger.LogCommandText(...) (command text + parameter snapshot with opt-in redaction) and ILogger.LogDbCommand(DbCommand, ...) (logs a live command directly). The library is intentionally narrow and grows one type at a time as needed.

Trimming / Native AOT: LogDbConnection, LogDbCommand, and the IReadOnlyDictionary<string, object?> overloads of LogCommandText are trim- and AOT-safe (verified by a PublishAot smoke in CI). The anonymous-object LogCommandText(..., object parameters, ...) overloads reflect over the parameter's runtime properties and are marked [RequiresUnreferencedCode] — in trimmed/AOT apps use the dictionary overload instead.


🪵 Entity Framework 6 companion

The optional Wolfgang.Extensions.Logging.Data.EntityFramework6 package wires these extension methods into the EF6 interceptor pipeline so a legacy EF6 app logs every command, connection, and transaction event with no per-query call sites. Register once at startup:

// At application startup, before any DbContext is used:
EntityFramework6Logging.AddLoggingInterceptors(
    logger,
    excludedParameterNames: new[] { "password" },   // optional — redacted in logged commands
    level: LogLevel.Information);                    // optional — defaults to Information

From then on, every DbContext in the process logs:

  • Commands — text + parameter snapshot (redacted), via LogDbCommand.
  • Connections — open/close lifecycle, with connection-string redaction, via LogDbConnection.
  • Transactions — commit / rollback.
  • Failures — surfaced at LogLevel.Error from the EF6 interception context.

DbInterception.Add is process-global and not idempotent, so AddLoggingInterceptors is a no-op if called again with the same logger instance. Targets net462; net48; netstandard2.1.

dotnet add package Wolfgang.Extensions.Logging.Data.EntityFramework6

🎯 Supported Frameworks

This repo ships two packages, each with its own TFM matrix:

Package Target Frameworks
Wolfgang.Extensions.Logging.Data net462, netstandard2.0, netstandard2.1, net10.0
Wolfgang.Extensions.Logging.Data.EntityFramework6 net462, net48, netstandard2.1

net462 is included so the library is usable from .NET Framework 4.6.2+ application hosts (existing System.Data.SqlClient consumers, classic web apps).

See each package's NuGet page for the authoritative per-TFM compatibility matrix.

🔍 Code Quality & Static Analysis

This project enforces strict code quality standards through 7 specialized analyzers and async-first custom rules:

  1. Microsoft.CodeAnalysis.NetAnalyzers — built-in .NET analyzers for correctness and performance
  2. Roslynator.Analyzers — advanced refactoring and code quality rules
  3. AsyncFixer — async/await best practices and anti-pattern detection
  4. Microsoft.VisualStudio.Threading.Analyzers — thread safety and async patterns
  5. Microsoft.CodeAnalysis.BannedApiAnalyzers — prevents usage of banned synchronous APIs
  6. Meziantou.Analyzer — comprehensive code quality rules
  7. SonarAnalyzer.CSharp — industry-standard code analysis

Async-First Enforcement

The repo uses BannedSymbols.txt to prohibit blocking APIs:

  • ❌ Task.Wait(), Task.Result — use await
  • ❌ Thread.Sleep() — use await Task.Delay()
  • ❌ Synchronous file I/O (File.ReadAllText) — use async equivalents
  • ❌ Synchronous stream operations — use ReadAsync() / WriteAsync()
  • ❌ Parallel.For / Parallel.ForEach — use Task.WhenAll() or Parallel.ForEachAsync()
  • ❌ Obsolete APIs (WebClient, BinaryFormatter)

🛠️ Building from Source

Prerequisites

  • .NET 10.0 SDK (also need .NET 8 / 9 SDKs to run the full multi-targeting test matrix)
  • Optional: PowerShell Core for the formatting / build helper scripts

Build steps

# Clone
git clone https://github.com/Chris-Wolfgang/Extensions-Logging-Data.git
cd Extensions-Logging-Data

# Restore + build + test
dotnet restore
dotnet build --configuration Release
dotnet test  --configuration Release

# Format (PowerShell Core)
pwsh ./scripts/format.ps1

Building documentation locally

# Install DocFX once
dotnet tool update -g docfx

# Build + serve
cd docfx_project
docfx metadata
docfx build --serve   # http://localhost:8080

🤝 Contributing

Contributions are welcome — see CONTRIBUTING.md for code quality standards, build and test instructions, pull request guidelines, and analyzer configuration details.


🙏 Acknowledgments

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.1 979 8/21/2026
0.2.0 222 7/12/2026