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);
dotnet add package Byndyusoft.Data.Relational.Diagnostics
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.
Make sure you have installed all of the following prerequisites on your development machine:
- Git - Download & Install Git. OSX and Linux machines typically have this already installed.
- .NET (version 5.0 or higher) - Download & Install .NET Core.
- source code
- unit-tests
- 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