Table of Contents

Class EventDefinition<TParam1, TParam2>

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

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

public class EventDefinition<TParam1, TParam2> : EventDefinitionBase

Type Parameters

TParam1
TParam2
Inheritance
EventDefinition<TParam1, TParam2>
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, TParam1, TParam2, Exception?>>)

Creates an event definition instance.

public EventDefinition(ILoggingOptions loggingOptions, EventId eventId, LogLevel level, string eventIdCode, Func<LogLevel, Action<ILogger, TParam1, TParam2, 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, TParam1, TParam2, Exception>>

Function to create a cached delegate for logging the event.

Methods

GenerateMessage(TParam1, TParam2)

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(TParam1 arg1, TParam2 arg2)

Parameters

arg1 TParam1

The first message argument.

arg2 TParam2

The second message argument.

Returns

string

The message string.

Log<TLoggerCategory>(IDiagnosticsLogger<TLoggerCategory>, TParam1, TParam2)

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, TParam1 arg1, TParam2 arg2) where TLoggerCategory : LoggerCategory<TLoggerCategory>, new()

Parameters

logger IDiagnosticsLogger<TLoggerCategory>

The logger to which the event should be logged.

arg1 TParam1

The first message argument.

arg2 TParam2

The second message argument.

Type Parameters

TLoggerCategory

The DbLoggerCategory.