Skip to main content
.NETStandard2.0

Microsoft.Data.SqlClient Internal Logging - ETW EventSource for SqlClient tracing and diagnostics. This package is for internal use by other Microsoft.Data.SqlClient packages only and should not be referenced directly by application code.

Published
Sep 29, 2026
1mo ago
Total Downloads
56.3M
56,287,017

Install

dotnet add package Microsoft.Data.SqlClient.Internal.Logging --version 7.1.1
ProductVersions
.NET Standard
netstandard2.0

README

Microsoft.Data.SqlClient.Internal.Logging

NuGet NuGet Downloads

⚠️ Internal Package — Do Not Reference Directly

This package is intended for internal use by the SqlClient suite of packages only. It is not designed for direct consumption by application code and may undergo breaking changes without notice.

Description

This package provides ETW EventSource tracing and diagnostics for Microsoft.Data.SqlClient. It enables comprehensive logging and telemetry capabilities for SQL Server database operations.

Key Features

  • ETW EventSource Integration: Structured logging using Event Tracing for Windows (ETW)
  • Diagnostic Listeners: Hook into SqlClient diagnostic events
  • Performance Counters: Track connection pool and query performance metrics
  • Correlation Support: Integrate with distributed tracing systems

Supportability

This package supports:

  • .NET Standard 2.0 (compatible with .NET Framework 4.6.1+, .NET Core 2.0+, and .NET 5+)

Installation

Install the package via NuGet:

dotnet add package Microsoft.Data.SqlClient.Internal.Logging

Or via the Package Manager Console:

Install-Package Microsoft.Data.SqlClient.Internal.Logging

Getting Started

Enable ETW Tracing

Use tools like PerfView or Windows Performance Recorder to capture ETW events:

# Using PerfView
PerfView.exe collect /Providers=*Microsoft.Data.SqlClient.EventSource

Subscribe to Diagnostic Events

using System.Diagnostics;

// Subscribe to SqlClient diagnostic events
DiagnosticListener.AllListeners.Subscribe(new SqlClientObserver());

public class SqlClientObserver : IObserver<DiagnosticListener>
{
    public void OnNext(DiagnosticListener listener)
    {
        if (listener.Name == "SqlClientDiagnosticListener")
        {
            listener.Subscribe(new SqlClientEventObserver());
        }
    }

    public void OnError(Exception error) { }
    public void OnCompleted() { }
}

public class SqlClientEventObserver : IObserver<KeyValuePair<string, object>>
{
    public void OnNext(KeyValuePair<string, object> value)
    {
        Console.WriteLine($"Event: {value.Key}");
        // Process event data...
    }

    public void OnError(Exception error) { }
    public void OnCompleted() { }
}

Event Categories

The logging extension emits events in these categories:

Category Events
Connection Open, Close, Pool operations
Commands Before/After execution, Errors
Transactions Begin, Commit, Rollback
Pool Connection acquired/released, Pool sizing
Errors Exceptions, Retries, Timeouts

Documentation

License

This package is licensed under the MIT License.

Related Packages

Changes from Previous Version

No structural changes between v7.1.0 and v7.1.1.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

Compatibility metadata lists 1 target framework; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.