DbQueryLogging 1.0.1

.NET Standard 2.1
dotnet add package DbQueryLogging --version 1.0.1
NuGet\Install-Package DbQueryLogging -Version 1.0.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="DbQueryLogging" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DbQueryLogging --version 1.0.1
#r "nuget: DbQueryLogging, 1.0.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install DbQueryLogging as a Cake Addin
#addin nuget:?package=DbQueryLogging&version=1.0.1

// Install DbQueryLogging as a Cake Tool
#tool nuget:?package=DbQueryLogging&version=1.0.1


A simple wrapper on DbConnection and DbCommand that logs SQL statements into an ILogger instance

.NET Core

Nuget Package

.Net Standard 2.1



Use as the following:

var connection = new LoggedDbConnection(DbConnection, ILogger);


DbConnection : System.Data.Common.DbConnection

ILogger : Microsoft.Extensions.Logging.ILogger

Demo sample

A sample demo project is also available in the sources at : https://github.com/akarzazi/DbQueryLogging/tree/master/demo

using System;
using DbQueryLogging;
using Microsoft.Data.Sqlite;
using Microsoft.Extensions.Logging;

namespace Demo
    public class Program
        const string connectionString = "Data Source=InMemorySample;Mode=Memory;Cache=Shared";

        static void Main(string[] args)
            ILogger consoleLogger = new ConsoleLogger();

            using var connection = new LoggedDbConnection(new SqliteConnection(connectionString), consoleLogger);

            var queryCommand = connection.CreateCommand();
            queryCommand.CommandText = "SELECT @name, @age";
            queryCommand.Parameters.AddRange(new[] {
                    new SqliteParameter("@name", "Bob"),
                    new SqliteParameter("@age", 28)
            var result = queryCommand.ExecuteScalar();

        public class ConsoleLogger : ILogger
            public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
                Console.WriteLine(formatter(state, exception));

            public IDisposable BeginScope<TState>(TState state) => throw new NotImplementedException();
            public bool IsEnabled(LogLevel logLevel) => true;


- CommandType Text
- CommandText SELECT @name, @age
- Parameters
        @name = Bob
        @age = 28
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.1
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
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
1.0.1 391 4/27/2020
1.0.0 321 4/24/2020