Class EventDefinition
- Namespace
- Microsoft.EntityFrameworkCore.Diagnostics
- Assembly
- Microsoft.EntityFrameworkCore.dll
Defines metadata for an event with no parameters and a cached delegate to log the event with reduced allocations.
public class EventDefinition : EventDefinitionBase
- Inheritance
-
EventDefinition
- 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, Exception?>>)
Creates an event definition instance.
public EventDefinition(ILoggingOptions loggingOptions, EventId eventId, LogLevel level, string eventIdCode, Func<LogLevel, Action<ILogger, Exception?>> logActionFunc)
Parameters
loggingOptions
ILoggingOptionsLogging options.
eventId
EventIdThe EventId.
level
LogLevelThe LogLevel at which the event will be logged.
eventIdCode
stringA string representing the code that should be passed to ConfigureWarnings(Action<WarningsConfigurationBuilder>).
logActionFunc
Func<LogLevel, Action<ILogger, Exception>>Function to create a cached delegate for logging the event.
Methods
GenerateMessage()
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()
Returns
- string
The message string.
Log<TLoggerCategory>(IDiagnosticsLogger<TLoggerCategory>, Exception?)
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, Exception? exception = null) where TLoggerCategory : LoggerCategory<TLoggerCategory>, new()
Parameters
logger
IDiagnosticsLogger<TLoggerCategory>The logger to which the event should be logged.
exception
ExceptionOptional exception associated with the event.
Type Parameters
TLoggerCategory
The DbLoggerCategory.