Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Byndyusoft/Byndyusoft.Data.Relational.Diagnostics

Repository files navigation

(License) Nuget NuGet downloads

Usage

You can enable DbConnection diagnosting by calling AddDiagnosting() extension method over it.

await using var connection = new NpgsqlConnection(connectionString).AddDiagnosting();

Here is a simple diagnostic observer:

private sealed class Observer :
		IObserver<DiagnosticListener>,
		IObserver<KeyValuePair<string, object>>
{
	private readonly List<IDisposable> _subscriptions = new List<IDisposable>();

	void IObserver<DiagnosticListener>.OnNext(DiagnosticListener diagnosticListener)
	{
		if (diagnosticListener.Name == nameof(DbDiagnosticSource))
			_subscriptions.Add(diagnosticListener.Subscribe(this));
	}

	void IObserver<DiagnosticListener>.OnError(Exception error) { }

	void IObserver<DiagnosticListener>.OnCompleted()
	{
		_subscriptions.ForEach(x => x.Dispose());
		_subscriptions.Clear();
	}

	void IObserver<KeyValuePair<string, object>>.OnCompleted() { }

	public void OnError(Exception error) { }

	void IObserver<KeyValuePair<string, object>>.OnNext(KeyValuePair<string, object> value) =>
		Console.WriteLine(value);
}

Next you can consume diagnostic events. You can read more at DiagnosticSourceUsersGuide.

var observer = new Observer();
using var subscription = DiagnosticListener.AllListeners.Subscribe(observer);

Installing

dotnet add package Byndyusoft.Data.Relational.Diagnostics

Contributing

To contribute, you will need to setup your local environment, see prerequisites. For the contribution and workflow guide, see package development lifecycle.

A detailed overview on how to contribute can be found in the contributing guide.

Prerequisites

Make sure you have installed all of the following prerequisites on your development machine:

General folders layout

src

  • source code

tests

  • unit-tests

Package development lifecycle

  • Implement package logic in src
  • Add or addapt unit-tests (prefer before and simultaneously with coding) in tests
  • Add or change the documentation as needed
  • Open pull request in the correct branch. Target the project's master branch

Maintainers

github.maintain@byndyusoft.com