Table of Contents

Interface IRelationalCommandDiagnosticsLogger

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 IRelationalCommandDiagnosticsLogger : IDiagnosticsLogger<DbLoggerCategory.Database.Command>, 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

CommandCanceled(IRelationalConnection, DbCommand, DbContext?, DbCommandMethod, Guid, Guid, DateTimeOffset, TimeSpan, CommandSource)

Logs for the CommandCanceled event.

void CommandCanceled(IRelationalConnection connection, DbCommand command, DbContext? context, DbCommandMethod executeMethod, Guid commandId, Guid connectionId, DateTimeOffset startTime, TimeSpan duration, CommandSource commandSource)

Parameters

connection IRelationalConnection

The connection.

command DbCommand

The database command object.

context DbContext

The Microsoft.EntityFrameworkCore.DbContext currently being used, to null if not known.

executeMethod DbCommandMethod

Represents the method that will be called to execute the command.

commandId Guid

The correlation ID associated with the given DbCommand.

connectionId Guid

The correlation ID associated with the DbConnection being used.

startTime DateTimeOffset

The time that execution began.

duration TimeSpan

The amount of time that passed until the exception was raised.

commandSource CommandSource

Source of the command.

CommandCanceledAsync(IRelationalConnection, DbCommand, DbContext?, DbCommandMethod, Guid, Guid, DateTimeOffset, TimeSpan, CommandSource, CancellationToken)

Logs for the CommandCanceled event.

Task CommandCanceledAsync(IRelationalConnection connection, DbCommand command, DbContext? context, DbCommandMethod executeMethod, Guid commandId, Guid connectionId, DateTimeOffset startTime, TimeSpan duration, CommandSource commandSource, CancellationToken cancellationToken = default)

Parameters

connection IRelationalConnection

The connection.

command DbCommand

The database command object.

context DbContext

The Microsoft.EntityFrameworkCore.DbContext currently being used, to null if not known.

executeMethod DbCommandMethod

Represents the method that will be called to execute the command.

commandId Guid

The correlation ID associated with the given DbCommand.

connectionId Guid

The correlation ID associated with the DbConnection being used.

startTime DateTimeOffset

The time that execution began.

duration TimeSpan

The amount of time that passed until the exception was raised.

commandSource CommandSource

Source of the command.

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.

CommandCreated(IRelationalConnection, DbCommand, DbCommandMethod, DbContext?, Guid, Guid, DateTimeOffset, TimeSpan, CommandSource)

Logs for the CommandCreated event.

DbCommand CommandCreated(IRelationalConnection connection, DbCommand command, DbCommandMethod commandMethod, DbContext? context, Guid commandId, Guid connectionId, DateTimeOffset startTime, TimeSpan duration, CommandSource commandSource)

Parameters

connection IRelationalConnection

The connection.

command DbCommand

The database command object.

commandMethod DbCommandMethod

The type of method that will be called on this command.

context DbContext

The Microsoft.EntityFrameworkCore.DbContext currently being used, to null if not known.

commandId Guid

The correlation ID associated with the given DbCommand.

connectionId Guid

The correlation ID associated with the DbConnection being used.

startTime DateTimeOffset

The time that execution began.

duration TimeSpan

The duration of the command creation.

commandSource CommandSource

Source of the command.

Returns

DbCommand

An intercepted result.

CommandCreating(IRelationalConnection, DbCommandMethod, DbContext?, Guid, Guid, DateTimeOffset, CommandSource)

Logs for the CommandCreating event.

InterceptionResult<DbCommand> CommandCreating(IRelationalConnection connection, DbCommandMethod commandMethod, DbContext? context, Guid commandId, Guid connectionId, DateTimeOffset startTime, CommandSource commandSource)

Parameters

connection IRelationalConnection

The connection.

commandMethod DbCommandMethod

The type of method that will be called on this command.

context DbContext

The Microsoft.EntityFrameworkCore.DbContext currently being used, to null if not known.

commandId Guid

The correlation ID associated with the given DbCommand.

connectionId Guid

The correlation ID associated with the DbConnection being used.

startTime DateTimeOffset

The time that execution began.

commandSource CommandSource

Source of the command.

Returns

InterceptionResult<DbCommand>

An intercepted result.

CommandError(IRelationalConnection, DbCommand, DbContext?, DbCommandMethod, Guid, Guid, Exception, DateTimeOffset, TimeSpan, CommandSource)

Logs for the CommandError event.

void CommandError(IRelationalConnection connection, DbCommand command, DbContext? context, DbCommandMethod executeMethod, Guid commandId, Guid connectionId, Exception exception, DateTimeOffset startTime, TimeSpan duration, CommandSource commandSource)

Parameters

connection IRelationalConnection

The connection.

command DbCommand

The database command object.

context DbContext

The Microsoft.EntityFrameworkCore.DbContext currently being used, to null if not known.

executeMethod DbCommandMethod

Represents the method that will be called to execute the command.

commandId Guid

The correlation ID associated with the given DbCommand.

connectionId Guid

The correlation ID associated with the DbConnection being used.

exception Exception

The exception that caused this failure.

startTime DateTimeOffset

The time that execution began.

duration TimeSpan

The amount of time that passed until the exception was raised.

commandSource CommandSource

Source of the command.

CommandErrorAsync(IRelationalConnection, DbCommand, DbContext?, DbCommandMethod, Guid, Guid, Exception, DateTimeOffset, TimeSpan, CommandSource, CancellationToken)

Logs for the CommandError event.

Task CommandErrorAsync(IRelationalConnection connection, DbCommand command, DbContext? context, DbCommandMethod executeMethod, Guid commandId, Guid connectionId, Exception exception, DateTimeOffset startTime, TimeSpan duration, CommandSource commandSource, CancellationToken cancellationToken = default)

Parameters

connection IRelationalConnection

The connection.

command DbCommand

The database command object.

context DbContext

The Microsoft.EntityFrameworkCore.DbContext currently being used, to null if not known.

executeMethod DbCommandMethod

Represents the method that will be called to execute the command.

commandId Guid

The correlation ID associated with the given DbCommand.

connectionId Guid

The correlation ID associated with the DbConnection being used.

exception Exception

The exception that caused this failure.

startTime DateTimeOffset

The time that execution began.

duration TimeSpan

The amount of time that passed until the exception was raised.

commandSource CommandSource

Source of the command.

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.

CommandInitialized(IRelationalConnection, DbCommand, DbCommandMethod, DbContext?, Guid, Guid, DateTimeOffset, TimeSpan, CommandSource)

Logs for the CommandInitialized event.

DbCommand CommandInitialized(IRelationalConnection connection, DbCommand command, DbCommandMethod commandMethod, DbContext? context, Guid commandId, Guid connectionId, DateTimeOffset startTime, TimeSpan duration, CommandSource commandSource)

Parameters

connection IRelationalConnection

The connection.

command DbCommand

The database command object.

commandMethod DbCommandMethod

The type of method that will be called on this command.

context DbContext

The Microsoft.EntityFrameworkCore.DbContext currently being used, to null if not known.

commandId Guid

The correlation ID associated with the given DbCommand.

connectionId Guid

The correlation ID associated with the DbConnection being used.

startTime DateTimeOffset

The time that execution began.

duration TimeSpan

The duration of the command creation.

commandSource CommandSource

Source of the command.

Returns

DbCommand

An intercepted result.

CommandNonQueryExecuted(IRelationalConnection, DbCommand, DbContext?, Guid, Guid, int, DateTimeOffset, TimeSpan, CommandSource)

Logs for the CommandExecuted event.

int CommandNonQueryExecuted(IRelationalConnection connection, DbCommand command, DbContext? context, Guid commandId, Guid connectionId, int methodResult, DateTimeOffset startTime, TimeSpan duration, CommandSource commandSource)

Parameters

connection IRelationalConnection

The connection.

command DbCommand

The database command object.

context DbContext

The Microsoft.EntityFrameworkCore.DbContext currently being used, to null if not known.

commandId Guid

The correlation ID associated with the given DbCommand.

connectionId Guid

The correlation ID associated with the DbConnection being used.

methodResult int

The return value from the underlying method execution.

startTime DateTimeOffset

The time that execution began.

duration TimeSpan

The duration of the command execution, not including consuming results.

commandSource CommandSource

Source of the command.

Returns

int

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

CommandNonQueryExecutedAsync(IRelationalConnection, DbCommand, DbContext?, Guid, Guid, int, DateTimeOffset, TimeSpan, CommandSource, CancellationToken)

Logs for the CommandExecuted event.

ValueTask<int> CommandNonQueryExecutedAsync(IRelationalConnection connection, DbCommand command, DbContext? context, Guid commandId, Guid connectionId, int methodResult, DateTimeOffset startTime, TimeSpan duration, CommandSource commandSource, CancellationToken cancellationToken = default)

Parameters

connection IRelationalConnection

The connection.

command DbCommand

The database command object.

context DbContext

The Microsoft.EntityFrameworkCore.DbContext currently being used, to null if not known.

commandId Guid

The correlation ID associated with the given DbCommand.

connectionId Guid

The correlation ID associated with the DbConnection being used.

methodResult int

The return value from the underlying method execution.

startTime DateTimeOffset

The time that execution began.

duration TimeSpan

The duration of the command execution, not including consuming results.

commandSource CommandSource

Source of the command.

cancellationToken CancellationToken

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

Returns

ValueTask<int>

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

Exceptions

OperationCanceledException

If the CancellationToken is canceled.

CommandNonQueryExecuting(IRelationalConnection, DbCommand, DbContext?, Guid, Guid, DateTimeOffset, CommandSource)

Logs for the CommandExecuting event.

InterceptionResult<int> CommandNonQueryExecuting(IRelationalConnection connection, DbCommand command, DbContext? context, Guid commandId, Guid connectionId, DateTimeOffset startTime, CommandSource commandSource)

Parameters

connection IRelationalConnection

The connection.

command DbCommand

The database command object.

context DbContext

The Microsoft.EntityFrameworkCore.DbContext currently being used, to null if not known.

commandId Guid

The correlation ID associated with the given DbCommand.

connectionId Guid

The correlation ID associated with the DbConnection being used.

startTime DateTimeOffset

The time that execution began.

commandSource CommandSource

Source of the command.

Returns

InterceptionResult<int>

An intercepted result.

CommandNonQueryExecutingAsync(IRelationalConnection, DbCommand, DbContext?, Guid, Guid, DateTimeOffset, CommandSource, CancellationToken)

Logs for the CommandExecuting event.

ValueTask<InterceptionResult<int>> CommandNonQueryExecutingAsync(IRelationalConnection connection, DbCommand command, DbContext? context, Guid commandId, Guid connectionId, DateTimeOffset startTime, CommandSource commandSource, CancellationToken cancellationToken = default)

Parameters

connection IRelationalConnection

The connection.

command DbCommand

The database command object.

context DbContext

The Microsoft.EntityFrameworkCore.DbContext currently being used, to null if not known.

commandId Guid

The correlation ID associated with the given DbCommand.

connectionId Guid

The correlation ID associated with the DbConnection being used.

startTime DateTimeOffset

The time that execution began.

commandSource CommandSource

Source of the command.

cancellationToken CancellationToken

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

Returns

ValueTask<InterceptionResult<int>>

An intercepted result.

Exceptions

OperationCanceledException

If the CancellationToken is canceled.

CommandReaderExecuted(IRelationalConnection, DbCommand, DbContext?, Guid, Guid, DbDataReader, DateTimeOffset, TimeSpan, CommandSource)

Logs for the CommandExecuted event.

DbDataReader CommandReaderExecuted(IRelationalConnection connection, DbCommand command, DbContext? context, Guid commandId, Guid connectionId, DbDataReader methodResult, DateTimeOffset startTime, TimeSpan duration, CommandSource commandSource)

Parameters

connection IRelationalConnection

The connection.

command DbCommand

The database command object.

context DbContext

The Microsoft.EntityFrameworkCore.DbContext currently being used, to null if not known.

commandId Guid

The correlation ID associated with the given DbCommand.

connectionId Guid

The correlation ID associated with the DbConnection being used.

methodResult DbDataReader

The return value from the underlying method execution.

startTime DateTimeOffset

The time that execution began.

duration TimeSpan

The duration of the command execution, not including consuming results.

commandSource CommandSource

Source of the command.

Returns

DbDataReader

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

CommandReaderExecutedAsync(IRelationalConnection, DbCommand, DbContext?, Guid, Guid, DbDataReader, DateTimeOffset, TimeSpan, CommandSource, CancellationToken)

Logs for the CommandExecuted event.

ValueTask<DbDataReader> CommandReaderExecutedAsync(IRelationalConnection connection, DbCommand command, DbContext? context, Guid commandId, Guid connectionId, DbDataReader methodResult, DateTimeOffset startTime, TimeSpan duration, CommandSource commandSource, CancellationToken cancellationToken = default)

Parameters

connection IRelationalConnection

The connection.

command DbCommand

The database command object.

context DbContext

The Microsoft.EntityFrameworkCore.DbContext currently being used, to null if not known.

commandId Guid

The correlation ID associated with the given DbCommand.

connectionId Guid

The correlation ID associated with the DbConnection being used.

methodResult DbDataReader

The return value from the underlying method execution.

startTime DateTimeOffset

The time that execution began.

duration TimeSpan

The duration of the command execution, not including consuming results.

commandSource CommandSource

Source of the command.

cancellationToken CancellationToken

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

Returns

ValueTask<DbDataReader>

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

Exceptions

OperationCanceledException

If the CancellationToken is canceled.

CommandReaderExecuting(IRelationalConnection, DbCommand, DbContext?, Guid, Guid, DateTimeOffset, CommandSource)

Logs for the CommandExecuting event.

InterceptionResult<DbDataReader> CommandReaderExecuting(IRelationalConnection connection, DbCommand command, DbContext? context, Guid commandId, Guid connectionId, DateTimeOffset startTime, CommandSource commandSource)

Parameters

connection IRelationalConnection

The connection.

command DbCommand

The database command object.

context DbContext

The Microsoft.EntityFrameworkCore.DbContext currently being used, to null if not known.

commandId Guid

The correlation ID associated with the given DbCommand.

connectionId Guid

The correlation ID associated with the DbConnection being used.

startTime DateTimeOffset

The time that execution began.

commandSource CommandSource

Source of the command.

Returns

InterceptionResult<DbDataReader>

An intercepted result.

CommandReaderExecutingAsync(IRelationalConnection, DbCommand, DbContext?, Guid, Guid, DateTimeOffset, CommandSource, CancellationToken)

Logs for the CommandExecuting event.

ValueTask<InterceptionResult<DbDataReader>> CommandReaderExecutingAsync(IRelationalConnection connection, DbCommand command, DbContext? context, Guid commandId, Guid connectionId, DateTimeOffset startTime, CommandSource commandSource, CancellationToken cancellationToken = default)

Parameters

connection IRelationalConnection

The connection.

command DbCommand

The database command object.

context DbContext

The Microsoft.EntityFrameworkCore.DbContext currently being used, to null if not known.

commandId Guid

The correlation ID associated with the given DbCommand.

connectionId Guid

The correlation ID associated with the DbConnection being used.

startTime DateTimeOffset

The time that execution began.

commandSource CommandSource

Source of the command.

cancellationToken CancellationToken

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

Returns

ValueTask<InterceptionResult<DbDataReader>>

An intercepted result.

Exceptions

OperationCanceledException

If the CancellationToken is canceled.

CommandScalarExecuted(IRelationalConnection, DbCommand, DbContext?, Guid, Guid, object?, DateTimeOffset, TimeSpan, CommandSource)

Logs for the CommandExecuted event.

object? CommandScalarExecuted(IRelationalConnection connection, DbCommand command, DbContext? context, Guid commandId, Guid connectionId, object? methodResult, DateTimeOffset startTime, TimeSpan duration, CommandSource commandSource)

Parameters

connection IRelationalConnection

The connection.

command DbCommand

The database command object.

context DbContext

The Microsoft.EntityFrameworkCore.DbContext currently being used, to null if not known.

commandId Guid

The correlation ID associated with the given DbCommand.

connectionId Guid

The correlation ID associated with the DbConnection being used.

methodResult object

The return value from the underlying method execution.

startTime DateTimeOffset

The time that execution began.

duration TimeSpan

The duration of the command execution, not including consuming results.

commandSource CommandSource

Source of the command.

Returns

object

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

CommandScalarExecutedAsync(IRelationalConnection, DbCommand, DbContext?, Guid, Guid, object?, DateTimeOffset, TimeSpan, CommandSource, CancellationToken)

Logs for the CommandExecuted event.

ValueTask<object?> CommandScalarExecutedAsync(IRelationalConnection connection, DbCommand command, DbContext? context, Guid commandId, Guid connectionId, object? methodResult, DateTimeOffset startTime, TimeSpan duration, CommandSource commandSource, CancellationToken cancellationToken = default)

Parameters

connection IRelationalConnection

The connection.

command DbCommand

The database command object.

context DbContext

The Microsoft.EntityFrameworkCore.DbContext currently being used, to null if not known.

commandId Guid

The correlation ID associated with the given DbCommand.

connectionId Guid

The correlation ID associated with the DbConnection being used.

methodResult object

The return value from the underlying method execution.

startTime DateTimeOffset

The time that execution began.

duration TimeSpan

The duration of the command execution, not including consuming results.

commandSource CommandSource

Source of the command.

cancellationToken CancellationToken

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

Returns

ValueTask<object>

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

Exceptions

OperationCanceledException

If the CancellationToken is canceled.

CommandScalarExecuting(IRelationalConnection, DbCommand, DbContext?, Guid, Guid, DateTimeOffset, CommandSource)

Logs for the CommandExecuting event.

InterceptionResult<object> CommandScalarExecuting(IRelationalConnection connection, DbCommand command, DbContext? context, Guid commandId, Guid connectionId, DateTimeOffset startTime, CommandSource commandSource)

Parameters

connection IRelationalConnection

The connection.

command DbCommand

The database command object.

context DbContext

The Microsoft.EntityFrameworkCore.DbContext currently being used, to null if not known.

commandId Guid

The correlation ID associated with the given DbCommand.

connectionId Guid

The correlation ID associated with the DbConnection being used.

startTime DateTimeOffset

The time that execution began.

commandSource CommandSource

Source of the command.

Returns

InterceptionResult<object>

An intercepted result.

CommandScalarExecutingAsync(IRelationalConnection, DbCommand, DbContext?, Guid, Guid, DateTimeOffset, CommandSource, CancellationToken)

Logs for the CommandExecuting event.

ValueTask<InterceptionResult<object>> CommandScalarExecutingAsync(IRelationalConnection connection, DbCommand command, DbContext? context, Guid commandId, Guid connectionId, DateTimeOffset startTime, CommandSource commandSource, CancellationToken cancellationToken = default)

Parameters

connection IRelationalConnection

The connection.

command DbCommand

The database command object.

context DbContext

The Microsoft.EntityFrameworkCore.DbContext currently being used, to null if not known.

commandId Guid

The correlation ID associated with the given DbCommand.

connectionId Guid

The correlation ID associated with the DbConnection being used.

startTime DateTimeOffset

The time that execution began.

commandSource CommandSource

Source of the command.

cancellationToken CancellationToken

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

Returns

ValueTask<InterceptionResult<object>>

An intercepted result.

Exceptions

OperationCanceledException

If the CancellationToken is canceled.

DataReaderClosing(IRelationalConnection, DbCommand, DbDataReader, Guid, int, int, DateTimeOffset)

Logs for the DataReaderClosing event.

InterceptionResult DataReaderClosing(IRelationalConnection connection, DbCommand command, DbDataReader dataReader, Guid commandId, int recordsAffected, int readCount, DateTimeOffset startTime)

Parameters

connection IRelationalConnection

The connection.

command DbCommand

The database command object.

dataReader DbDataReader

The data reader.

commandId Guid

The correlation ID associated with the given DbCommand.

recordsAffected int

The number of records in the database that were affected.

readCount int

The number of records that were read.

startTime DateTimeOffset

The time that the operation was started.

Returns

InterceptionResult

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

DataReaderClosingAsync(IRelationalConnection, DbCommand, DbDataReader, Guid, int, int, DateTimeOffset)

Logs for the DataReaderClosing event.

ValueTask<InterceptionResult> DataReaderClosingAsync(IRelationalConnection connection, DbCommand command, DbDataReader dataReader, Guid commandId, int recordsAffected, int readCount, DateTimeOffset startTime)

Parameters

connection IRelationalConnection

The connection.

command DbCommand

The database command object.

dataReader DbDataReader

The data reader.

commandId Guid

The correlation ID associated with the given DbCommand.

recordsAffected int

The number of records in the database that were affected.

readCount int

The number of records that were read.

startTime DateTimeOffset

The time that the operation was started.

Returns

ValueTask<InterceptionResult>

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

DataReaderDisposing(IRelationalConnection, DbCommand, DbDataReader, Guid, int, int, DateTimeOffset, TimeSpan)

Logs for the DataReaderDisposing event.

InterceptionResult DataReaderDisposing(IRelationalConnection connection, DbCommand command, DbDataReader dataReader, Guid commandId, int recordsAffected, int readCount, DateTimeOffset startTime, TimeSpan duration)

Parameters

connection IRelationalConnection

The connection.

command DbCommand

The database command object.

dataReader DbDataReader

The data reader.

commandId Guid

The correlation ID associated with the given DbCommand.

recordsAffected int

The number of records in the database that were affected.

readCount int

The number of records that were read.

startTime DateTimeOffset

The time that the operation was started.

duration TimeSpan

The elapsed time from when the operation was started.

Returns

InterceptionResult

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

ShouldLogCommandCreate(DateTimeOffset)

Whether CommandCreating or CommandCreated need to be logged.

bool ShouldLogCommandCreate(DateTimeOffset now)

Parameters

now DateTimeOffset

Returns

bool

ShouldLogCommandExecute(DateTimeOffset)

Whether CommandExecuting or CommandExecuted need to be logged.

bool ShouldLogCommandExecute(DateTimeOffset now)

Parameters

now DateTimeOffset

Returns

bool

ShouldLogDataReaderClose(DateTimeOffset)

Whether DataReaderClosing needs to be logged.

bool ShouldLogDataReaderClose(DateTimeOffset now)

Parameters

now DateTimeOffset

Returns

bool

ShouldLogDataReaderDispose(DateTimeOffset)

Whether DataReaderDisposing needs to be logged.

bool ShouldLogDataReaderDispose(DateTimeOffset now)

Parameters

now DateTimeOffset

Returns

bool