Table of Contents

Interface IRelationalConnectionDiagnosticsLogger

Namespace
Microsoft.EntityFrameworkCore.Diagnostics
Assembly
Microsoft.EntityFrameworkCore.Relational.dll

An Microsoft.EntityFrameworkCore.Diagnostics.IDiagnosticsLogger<> with some extra functionality suited for high-performance logging.

public interface IRelationalConnectionDiagnosticsLogger : IDiagnosticsLogger<DbLoggerCategory.Database.Connection>, IDiagnosticsLogger

Remarks

The service lifetime is Scoped. This means that each Microsoft.EntityFrameworkCore.DbContext instance will use its own instance of this service. The implementation may depend on other services registered with any lifetime. The implementation does not need to be thread-safe.

See Implementation of database providers and extensions for more information and examples.

Methods

ConnectionClosed(IRelationalConnection, DateTimeOffset, TimeSpan)

Logs for the ConnectionClosed event.

void ConnectionClosed(IRelationalConnection connection, DateTimeOffset startTime, TimeSpan duration)

Parameters

connection IRelationalConnection

The connection.

startTime DateTimeOffset

The time that the operation was started.

duration TimeSpan

The amount of time before the connection was closed.

ConnectionClosedAsync(IRelationalConnection, DateTimeOffset, TimeSpan)

Logs for the ConnectionClosed event.

Task ConnectionClosedAsync(IRelationalConnection connection, DateTimeOffset startTime, TimeSpan duration)

Parameters

connection IRelationalConnection

The connection.

startTime DateTimeOffset

The time that the operation was started.

duration TimeSpan

The amount of time before the connection was closed.

Returns

Task

A Task representing the async operation.

ConnectionClosing(IRelationalConnection, DateTimeOffset)

Logs for the ConnectionClosing event.

InterceptionResult ConnectionClosing(IRelationalConnection connection, DateTimeOffset startTime)

Parameters

connection IRelationalConnection

The connection.

startTime DateTimeOffset

The time that the operation was started.

Returns

InterceptionResult

The result of execution, which may have been modified by an interceptor.

ConnectionClosingAsync(IRelationalConnection, DateTimeOffset)

Logs for the ConnectionClosing event.

ValueTask<InterceptionResult> ConnectionClosingAsync(IRelationalConnection connection, DateTimeOffset startTime)

Parameters

connection IRelationalConnection

The connection.

startTime DateTimeOffset

The time that the operation was started.

Returns

ValueTask<InterceptionResult>

A Task representing the async operation.

ConnectionCreated(IRelationalConnection, DateTimeOffset, TimeSpan)

Logs for the ConnectionCreated event.

DbConnection ConnectionCreated(IRelationalConnection connection, DateTimeOffset startTime, TimeSpan duration)

Parameters

connection IRelationalConnection

The connection.

startTime DateTimeOffset

The time that the operation was started.

duration TimeSpan

The amount of time it took to create the connection.

Returns

DbConnection

ConnectionCreating(IRelationalConnection, DateTimeOffset)

Logs for the ConnectionCreating event.

InterceptionResult<DbConnection> ConnectionCreating(IRelationalConnection connection, DateTimeOffset startTime)

Parameters

connection IRelationalConnection

The connection.

startTime DateTimeOffset

The time that the operation was started.

Returns

InterceptionResult<DbConnection>

The result of execution, which may have been modified by an interceptor.

ConnectionDisposed(IRelationalConnection, DateTimeOffset, TimeSpan)

Logs for the ConnectionDisposed event.

void ConnectionDisposed(IRelationalConnection connection, DateTimeOffset startTime, TimeSpan duration)

Parameters

connection IRelationalConnection

The connection.

startTime DateTimeOffset

The time that the operation was started.

duration TimeSpan

The amount of time it took to dispose the connection.

ConnectionDisposedAsync(IRelationalConnection, DateTimeOffset, TimeSpan)

Logs for the ConnectionDisposed event.

Task ConnectionDisposedAsync(IRelationalConnection connection, DateTimeOffset startTime, TimeSpan duration)

Parameters

connection IRelationalConnection

The connection.

startTime DateTimeOffset

The time that the operation was started.

duration TimeSpan

The amount of time it took to dispose the connection.

Returns

Task

A Task representing the async operation.

ConnectionDisposing(IRelationalConnection, DateTimeOffset)

Logs for the ConnectionDisposing event.

InterceptionResult ConnectionDisposing(IRelationalConnection connection, DateTimeOffset startTime)

Parameters

connection IRelationalConnection

The connection.

startTime DateTimeOffset

The time that the operation was started.

Returns

InterceptionResult

The result of execution, which may have been modified by an interceptor.

ConnectionDisposingAsync(IRelationalConnection, DateTimeOffset)

Logs for the ConnectionDisposing event.

ValueTask<InterceptionResult> ConnectionDisposingAsync(IRelationalConnection connection, DateTimeOffset startTime)

Parameters

connection IRelationalConnection

The connection.

startTime DateTimeOffset

The time that the operation was started.

Returns

ValueTask<InterceptionResult>

A Task representing the async operation.

ConnectionError(IRelationalConnection, Exception, DateTimeOffset, TimeSpan, bool)

Logs for the ConnectionError event.

void ConnectionError(IRelationalConnection connection, Exception exception, DateTimeOffset startTime, TimeSpan duration, bool logErrorAsDebug)

Parameters

connection IRelationalConnection

The connection.

exception Exception

The exception representing the error.

startTime DateTimeOffset

The time that the operation was started.

duration TimeSpan

The elapsed time before the operation failed.

logErrorAsDebug bool

A flag indicating the exception is being handled and so it should be logged at Debug level.

ConnectionErrorAsync(IRelationalConnection, Exception, DateTimeOffset, TimeSpan, bool, CancellationToken)

Logs for the ConnectionError event.

Task ConnectionErrorAsync(IRelationalConnection connection, Exception exception, DateTimeOffset startTime, TimeSpan duration, bool logErrorAsDebug, CancellationToken cancellationToken = default)

Parameters

connection IRelationalConnection

The connection.

exception Exception

The exception representing the error.

startTime DateTimeOffset

The time that the operation was started.

duration TimeSpan

The elapsed time before the operation failed.

logErrorAsDebug bool

A flag indicating the exception is being handled and so it should be logged at Debug level.

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

Task

A Task representing the async operation.

Exceptions

OperationCanceledException

If the CancellationToken is canceled.

ConnectionOpened(IRelationalConnection, DateTimeOffset, TimeSpan)

Logs for the ConnectionOpened event.

void ConnectionOpened(IRelationalConnection connection, DateTimeOffset startTime, TimeSpan duration)

Parameters

connection IRelationalConnection

The connection.

startTime DateTimeOffset

The time that the operation was started.

duration TimeSpan

The amount of time before the connection was opened.

ConnectionOpenedAsync(IRelationalConnection, DateTimeOffset, TimeSpan, CancellationToken)

Logs for the ConnectionOpened event.

Task ConnectionOpenedAsync(IRelationalConnection connection, DateTimeOffset startTime, TimeSpan duration, CancellationToken cancellationToken = default)

Parameters

connection IRelationalConnection

The connection.

startTime DateTimeOffset

The time that the operation was started.

duration TimeSpan

The amount of time before the connection was opened.

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

Task

A Task representing the async operation.

Exceptions

OperationCanceledException

If the CancellationToken is canceled.

ConnectionOpening(IRelationalConnection, DateTimeOffset)

Logs for the ConnectionOpening event.

InterceptionResult ConnectionOpening(IRelationalConnection connection, DateTimeOffset startTime)

Parameters

connection IRelationalConnection

The connection.

startTime DateTimeOffset

The time that the operation was started.

Returns

InterceptionResult

The result of execution, which may have been modified by an interceptor.

ConnectionOpeningAsync(IRelationalConnection, DateTimeOffset, CancellationToken)

Logs for the ConnectionOpening event.

ValueTask<InterceptionResult> ConnectionOpeningAsync(IRelationalConnection connection, DateTimeOffset startTime, CancellationToken cancellationToken)

Parameters

connection IRelationalConnection

The connection.

startTime DateTimeOffset

The time that the operation was started.

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

ValueTask<InterceptionResult>

A Task representing the async operation.

Exceptions

OperationCanceledException

If the CancellationToken is canceled.

ShouldLogConnectionClose(DateTimeOffset)

Whether ConnectionClosing or ConnectionClosed need to be logged.

bool ShouldLogConnectionClose(DateTimeOffset now)

Parameters

now DateTimeOffset

Returns

bool

ShouldLogConnectionCreate(DateTimeOffset)

Whether ConnectionCreating or ConnectionCreated need to be logged.

bool ShouldLogConnectionCreate(DateTimeOffset now)

Parameters

now DateTimeOffset

Returns

bool

ShouldLogConnectionDispose(DateTimeOffset)

Whether ConnectionDisposing or ConnectionDisposed need to be logged.

bool ShouldLogConnectionDispose(DateTimeOffset now)

Parameters

now DateTimeOffset

Returns

bool

ShouldLogConnectionOpen(DateTimeOffset)

Whether ConnectionOpening or ConnectionOpened need to be logged.

bool ShouldLogConnectionOpen(DateTimeOffset now)

Parameters

now DateTimeOffset

Returns

bool