Table of Contents

Class EventDefinition<TParam>

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

Defines metadata for an event with one parameter and a cached delegate to log the event with reduced allocations.

public class EventDefinition<TParam> : EventDefinitionBase

Type Parameters

TParam
Inheritance
EventDefinition<TParam>
Inherited Members

Remarks

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

Constructors

EventDefinition(ILoggingOptions, EventId, LogLevel, string, Func<LogLevel, Action<ILogger, TParam, Exception?>>)

Creates an event definition instance.

public EventDefinition(ILoggingOptions loggingOptions, EventId eventId, LogLevel level, string eventIdCode, Func<LogLevel, Action<ILogger, TParam, Exception?>> logActionFunc)

Parameters

loggingOptions ILoggingOptions

Logging options.

eventId EventId

The EventId.

level LogLevel

The LogLevel at which the event will be logged.

eventIdCode string

A string representing the code that should be passed to ConfigureWarnings(Action<WarningsConfigurationBuilder>).

logActionFunc Func<LogLevel, Action<ILogger, TParam, Exception>>

Function to create a cached delegate for logging the event.

Methods

GenerateMessage(TParam)

Generates the message that would be logged without logging it. Typically used for throwing an exception in warning-as-error cases.

public virtual string GenerateMessage(TParam arg)

Parameters

arg TParam

The message argument.

Returns

string

The message string.

Log<TLoggerCategory>(IDiagnosticsLogger<TLoggerCategory>, TParam)

Logs the event, or throws if the event has been configured to be treated as an error.

public virtual void Log<TLoggerCategory>(IDiagnosticsLogger<TLoggerCategory> logger, TParam arg) where TLoggerCategory : LoggerCategory<TLoggerCategory>, new()

Parameters

logger IDiagnosticsLogger<TLoggerCategory>

The logger to which the event should be logged.

arg TParam

Message argument.

Type Parameters

TLoggerCategory

The DbLoggerCategory.