DbQueryLogging 1.0.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 and Polyglot Notebooks. 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                

DbQueryLogging

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

.NET Core

Nuget Package

.Net Standard 2.1

https://www.nuget.org/packages/DbQueryLogging/

Usage

Use as the following:

var connection = new LoggedDbConnection(DbConnection, ILogger);

Where

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);
            connection.Open();

            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;
        }
    }
}

Output

Executing
- CommandType Text
- CommandText SELECT @name, @age
- Parameters
        @name = Bob
        @age = 28
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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
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
1.0.1 3,309 4/27/2020
1.0.0 446 4/24/2020