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
<PackageReference Include="Wolfgang.Extensions.Logging.Data.EntityFramework6" Version="0.2.1" />
<PackageVersion Include="Wolfgang.Extensions.Logging.Data.EntityFramework6" Version="0.2.1" />
<PackageReference Include="Wolfgang.Extensions.Logging.Data.EntityFramework6" />
paket add Wolfgang.Extensions.Logging.Data.EntityFramework6 --version 0.2.1
#r "nuget: Wolfgang.Extensions.Logging.Data.EntityFramework6, 0.2.1"
#:package Wolfgang.Extensions.Logging.Data.EntityFramework6@0.2.1
#addin nuget:?package=Wolfgang.Extensions.Logging.Data.EntityFramework6&version=0.2.1
#tool nuget:?package=Wolfgang.Extensions.Logging.Data.EntityFramework6&version=0.2.1
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.
📦 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
- GitHub Repository: https://github.com/Chris-Wolfgang/Extensions-Logging-Data
- API Documentation: https://Chris-Wolfgang.github.io/Extensions-Logging-Data/
- CHANGELOG: CHANGELOG.md
- Contributing Guide: CONTRIBUTING.md
- Architecture Decision Records: docs/adr/
- Reproducible builds (independent verification): docs/REPRODUCIBLE-BUILDS.md
- Migration guides: docs/migrations/
- Disaster recovery runbook: docs/DISASTER-RECOVERY.md
- DocFX Version Picker Troubleshooting: docs/DOCFX-VERSION-PICKER.md
🚀 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 theIReadOnlyDictionary<string, object?>overloads ofLogCommandTextare trim- and AOT-safe (verified by aPublishAotsmoke in CI). The anonymous-objectLogCommandText(..., 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.Errorfrom 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:
- Microsoft.CodeAnalysis.NetAnalyzers — built-in .NET analyzers for correctness and performance
- Roslynator.Analyzers — advanced refactoring and code quality rules
- AsyncFixer — async/await best practices and anti-pattern detection
- Microsoft.VisualStudio.Threading.Analyzers — thread safety and async patterns
- Microsoft.CodeAnalysis.BannedApiAnalyzers — prevents usage of banned synchronous APIs
- Meziantou.Analyzer — comprehensive code quality rules
- SonarAnalyzer.CSharp — industry-standard code analysis
Async-First Enforcement
The repo uses BannedSymbols.txt to prohibit blocking APIs:
- ❌
Task.Wait(),Task.Result— useawait - ❌
Thread.Sleep()— useawait Task.Delay() - ❌ Synchronous file I/O (
File.ReadAllText) — use async equivalents - ❌ Synchronous stream operations — use
ReadAsync()/WriteAsync() - ❌
Parallel.For/Parallel.ForEach— useTask.WhenAll()orParallel.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
- Microsoft.Extensions.Logging — the
ILoggerabstraction this library extends - System.Data.Common.DbConnectionStringBuilder — the parser the redaction logic is built around
- The broader Wolfgang.Extensions.* family for the canonical CI / docs / packaging patterns this repo inherits
| Product | Versions 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. |
-
.NETFramework 4.6.2
- EntityFramework (>= 6.5.2)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.11)
- Wolfgang.Extensions.Logging.Data (>= 0.3.1)
-
.NETFramework 4.8
- EntityFramework (>= 6.5.2)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.11)
- Wolfgang.Extensions.Logging.Data (>= 0.3.1)
-
.NETStandard 2.1
- EntityFramework (>= 6.5.2)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.11)
- Wolfgang.Extensions.Logging.Data (>= 0.3.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.