Table of Contents

Interface IDiagnosticsLogger

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

Combines ILogger and DiagnosticSource for use by all EF Core logging so that events can be sent to both ILogger for ASP.NET and DiagnosticSource for everything else.

public interface IDiagnosticsLogger

Remarks

The service lifetime is Singleton. This means a single instance is used by many DbContext instances. The implementation must be thread-safe. This service cannot depend on services registered as Scoped.

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

Properties

DbContextLogger

IDbContextLogger DbContextLogger { get; }

Property Value

IDbContextLogger

Definitions

Caching for logging definitions.

LoggingDefinitions Definitions { get; }

Property Value

LoggingDefinitions

DiagnosticSource

DiagnosticSource DiagnosticSource { get; }

Property Value

DiagnosticSource

Interceptors

Holds registered interceptors, if any.

IInterceptors? Interceptors { get; }

Property Value

IInterceptors

Logger

The underlying ILogger.

ILogger Logger { get; }

Property Value

ILogger

Options

Entity Framework logging options.

ILoggingOptions Options { get; }

Property Value

ILoggingOptions

Methods

DispatchEventData(EventDefinitionBase, EventData, bool, bool)

Dispatches the given EventData to a DiagnosticSource, if enabled, and a IDbContextLogger, if enabled.

void DispatchEventData(EventDefinitionBase definition, EventData eventData, bool diagnosticSourceEnabled, bool simpleLogEnabled)

Parameters

definition EventDefinitionBase

The definition of the event to log.

eventData EventData

The event data.

diagnosticSourceEnabled bool

True to dispatch to a DiagnosticSource; false otherwise.

simpleLogEnabled bool

True to dispatch to a IDbContextLogger; false otherwise.

NeedsEventData(EventDefinitionBase, out bool, out bool)

Determines whether or not an EventData instance is needed based on whether or not there is a DiagnosticSource or an IDbContextLogger enabled for the given event.

bool NeedsEventData(EventDefinitionBase definition, out bool diagnosticSourceEnabled, out bool simpleLogEnabled)

Parameters

definition EventDefinitionBase

The definition of the event.

diagnosticSourceEnabled bool

Set to true if a DiagnosticSource is enabled; false otherwise.

simpleLogEnabled bool

True to true if a IDbContextLogger is enabled; false otherwise.

Returns

bool

true if either a diagnostic source or a LogTo logger is enabled; false otherwise.

NeedsEventData<TInterceptor>(EventDefinitionBase, out TInterceptor?, out bool, out bool)

Determines whether or not an EventData instance is needed based on whether or not there is a DiagnosticSource, an IDbContextLogger, or an IInterceptor enabled for the given event.

bool NeedsEventData<TInterceptor>(EventDefinitionBase definition, out TInterceptor? interceptor, out bool diagnosticSourceEnabled, out bool simpleLogEnabled) where TInterceptor : class, IInterceptor

Parameters

definition EventDefinitionBase

The definition of the event.

interceptor TInterceptor

The IInterceptor to use if enabled; otherwise null.

diagnosticSourceEnabled bool

Set to true if a DiagnosticSource is enabled; false otherwise.

simpleLogEnabled bool

True to true if a IDbContextLogger is enabled; false otherwise.

Returns

bool

true if either a diagnostic source, a LogTo logger, or an interceptor is enabled; false otherwise.

Type Parameters

TInterceptor

ShouldLog(EventDefinitionBase)

Checks whether or not the message should be sent to the ILogger.

bool ShouldLog(EventDefinitionBase definition)

Parameters

definition EventDefinitionBase

The definition of the event to log.

Returns

bool

true if ILogger logging is enabled and the event should not be ignored; false otherwise.

ShouldLogSensitiveData()

Gets a value indicating whether sensitive information should be written to the underlying logger. This also has the side effect of writing a warning to the log the first time sensitive data is logged.

bool ShouldLogSensitiveData()

Returns

bool