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
The IDbContextLogger.
IDbContextLogger DbContextLogger { get; }
Property Value
Definitions
Caching for logging definitions.
LoggingDefinitions Definitions { get; }
Property Value
DiagnosticSource
The DiagnosticSource.
DiagnosticSource DiagnosticSource { get; }
Property Value
Interceptors
Holds registered interceptors, if any.
IInterceptors? Interceptors { get; }
Property Value
Logger
The underlying ILogger.
ILogger Logger { get; }
Property Value
Options
Entity Framework logging options.
ILoggingOptions Options { get; }
Property Value
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
EventDefinitionBaseThe definition of the event to log.
eventData
EventDataThe event data.
diagnosticSourceEnabled
boolTrue to dispatch to a DiagnosticSource; false otherwise.
simpleLogEnabled
boolTrue 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
EventDefinitionBaseThe definition of the event.
diagnosticSourceEnabled
boolSet to true if a DiagnosticSource is enabled; false otherwise.
simpleLogEnabled
boolTrue to true if a IDbContextLogger is enabled; false otherwise.
Returns
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
EventDefinitionBaseThe definition of the event.
interceptor
TInterceptorThe IInterceptor to use if enabled; otherwise null.
diagnosticSourceEnabled
boolSet to true if a DiagnosticSource is enabled; false otherwise.
simpleLogEnabled
boolTrue 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
EventDefinitionBaseThe definition of the event to log.
Returns
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()