DbContextOptionsBuilder.LogTo Method

Definition

Overloads

LogTo(Action<String>, IEnumerable<String>, LogLevel, Nullable<DbContextLoggerOptions>)

Logs all events in the specified categories using the supplied action. For example, use optionsBuilder.LogTo(Console.WriteLine, new[] { DbLoggerCategory.Infrastructure.Name }) to log all events in the DbLoggerCategory.Infrastructure category.

LogTo(Action<String>, IEnumerable<EventId>, LogLevel, Nullable<DbContextLoggerOptions>)

Logs the specified events using the supplied action. For example, use optionsBuilder.LogTo(Console.WriteLine, new[] { CoreEventId.ContextInitialized }) to log the ContextInitialized event to the console.

LogTo(Action<String>, LogLevel, Nullable<DbContextLoggerOptions>)

Logs using the supplied action. For example, use optionsBuilder.LogTo(Console.WriteLine) to log to the console.

LogTo(Func<EventId,LogLevel,Boolean>, Action<EventData>)

Logs events to a custom logger delegate filtered by a custom filter delegate. The filter should return true to log a message, or false to filter it out of the log.

LogTo(Action<String>, Func<EventId,LogLevel,Boolean>, Nullable<DbContextLoggerOptions>)

Logs events filtered by a supplied custom filter delegate. The filter should return true to log a message, or false to filter it out of the log.

LogTo(Action<String>, IEnumerable<String>, LogLevel, Nullable<DbContextLoggerOptions>)

Logs all events in the specified categories using the supplied action. For example, use optionsBuilder.LogTo(Console.WriteLine, new[] { DbLoggerCategory.Infrastructure.Name }) to log all events in the DbLoggerCategory.Infrastructure category.

public virtual Microsoft.EntityFrameworkCore.DbContextOptionsBuilder LogTo (Action<string> action, System.Collections.Generic.IEnumerable<string> categories, Microsoft.Extensions.Logging.LogLevel minimumLevel = Microsoft.Extensions.Logging.LogLevel.Debug, Microsoft.EntityFrameworkCore.Diagnostics.DbContextLoggerOptions? options = default);
abstract member LogTo : Action<string> * seq<string> * Microsoft.Extensions.Logging.LogLevel * Nullable<Microsoft.EntityFrameworkCore.Diagnostics.DbContextLoggerOptions> -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
override this.LogTo : Action<string> * seq<string> * Microsoft.Extensions.Logging.LogLevel * Nullable<Microsoft.EntityFrameworkCore.Diagnostics.DbContextLoggerOptions> -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
Public Overridable Function LogTo (action As Action(Of String), categories As IEnumerable(Of String), Optional minimumLevel As LogLevel = Microsoft.Extensions.Logging.LogLevel.Debug, Optional options As Nullable(Of DbContextLoggerOptions) = Nothing) As DbContextOptionsBuilder

Parameters

action
Action<String>

Delegate called when there is a message to log.

categories
IEnumerable<String>

The DbLoggerCategory of each event to log.

minimumLevel
LogLevel

The minimum level of logging event to log. Defaults to Debug

options
Nullable<DbContextLoggerOptions>

Formatting options for log messages. Passing null (the default) means use DefaultWithLocalTime

Returns

The same builder instance so that multiple calls can be chained.

Remarks

Use the LogTo(Action<String>, LogLevel, Nullable<DbContextLoggerOptions>) overload for default logging of all events. Use the LogTo(Action<String>, IEnumerable<EventId>, LogLevel, Nullable<DbContextLoggerOptions>) overload to log only specific events. Use the LogTo(Action<String>, Func<EventId,LogLevel,Boolean>, Nullable<DbContextLoggerOptions>) overload to use a custom filter for events. Use the LogTo(Func<EventId,LogLevel,Boolean>, Action<EventData>) overload to log to a fully custom logger.

See Using DbContextOptions and Logging for more information and examples.

Applies to

LogTo(Action<String>, IEnumerable<EventId>, LogLevel, Nullable<DbContextLoggerOptions>)

Logs the specified events using the supplied action. For example, use optionsBuilder.LogTo(Console.WriteLine, new[] { CoreEventId.ContextInitialized }) to log the ContextInitialized event to the console.

public virtual Microsoft.EntityFrameworkCore.DbContextOptionsBuilder LogTo (Action<string> action, System.Collections.Generic.IEnumerable<Microsoft.Extensions.Logging.EventId> events, Microsoft.Extensions.Logging.LogLevel minimumLevel = Microsoft.Extensions.Logging.LogLevel.Debug, Microsoft.EntityFrameworkCore.Diagnostics.DbContextLoggerOptions? options = default);
abstract member LogTo : Action<string> * seq<Microsoft.Extensions.Logging.EventId> * Microsoft.Extensions.Logging.LogLevel * Nullable<Microsoft.EntityFrameworkCore.Diagnostics.DbContextLoggerOptions> -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
override this.LogTo : Action<string> * seq<Microsoft.Extensions.Logging.EventId> * Microsoft.Extensions.Logging.LogLevel * Nullable<Microsoft.EntityFrameworkCore.Diagnostics.DbContextLoggerOptions> -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
Public Overridable Function LogTo (action As Action(Of String), events As IEnumerable(Of EventId), Optional minimumLevel As LogLevel = Microsoft.Extensions.Logging.LogLevel.Debug, Optional options As Nullable(Of DbContextLoggerOptions) = Nothing) As DbContextOptionsBuilder

Parameters

action
Action<String>

Delegate called when there is a message to log.

events
IEnumerable<EventId>

The EventId of each event to log.

minimumLevel
LogLevel

The minimum level of logging event to log. Defaults to Debug

options
Nullable<DbContextLoggerOptions>

Formatting options for log messages. Passing null (the default) means use DefaultWithLocalTime

Returns

The same builder instance so that multiple calls can be chained.

Remarks

Use the LogTo(Action<String>, LogLevel, Nullable<DbContextLoggerOptions>) overload for default logging of all events. Use the LogTo(Action<String>, IEnumerable<String>, LogLevel, Nullable<DbContextLoggerOptions>) overload to log only events in specific categories. Use the LogTo(Action<String>, Func<EventId,LogLevel,Boolean>, Nullable<DbContextLoggerOptions>) overload to use a custom filter for events. Use the LogTo(Func<EventId,LogLevel,Boolean>, Action<EventData>) overload to log to a fully custom logger.

See Using DbContextOptions and Logging for more information and examples.

Applies to

LogTo(Action<String>, LogLevel, Nullable<DbContextLoggerOptions>)

Logs using the supplied action. For example, use optionsBuilder.LogTo(Console.WriteLine) to log to the console.

public virtual Microsoft.EntityFrameworkCore.DbContextOptionsBuilder LogTo (Action<string> action, Microsoft.Extensions.Logging.LogLevel minimumLevel = Microsoft.Extensions.Logging.LogLevel.Debug, Microsoft.EntityFrameworkCore.Diagnostics.DbContextLoggerOptions? options = default);
abstract member LogTo : Action<string> * Microsoft.Extensions.Logging.LogLevel * Nullable<Microsoft.EntityFrameworkCore.Diagnostics.DbContextLoggerOptions> -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
override this.LogTo : Action<string> * Microsoft.Extensions.Logging.LogLevel * Nullable<Microsoft.EntityFrameworkCore.Diagnostics.DbContextLoggerOptions> -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
Public Overridable Function LogTo (action As Action(Of String), Optional minimumLevel As LogLevel = Microsoft.Extensions.Logging.LogLevel.Debug, Optional options As Nullable(Of DbContextLoggerOptions) = Nothing) As DbContextOptionsBuilder

Parameters

action
Action<String>

Delegate called when there is a message to log.

minimumLevel
LogLevel

The minimum level of logging event to log. Defaults to Debug

options
Nullable<DbContextLoggerOptions>

Formatting options for log messages. Passing null (the default) means use DefaultWithLocalTime

Returns

The same builder instance so that multiple calls can be chained.

Remarks

This overload allows the minimum level of logging and the log formatting to be controlled. Use the LogTo(Action<String>, IEnumerable<EventId>, LogLevel, Nullable<DbContextLoggerOptions>) overload to log only specific events. Use the LogTo(Action<String>, IEnumerable<String>, LogLevel, Nullable<DbContextLoggerOptions>) overload to log only events in specific categories. Use the LogTo(Action<String>, Func<EventId,LogLevel,Boolean>, Nullable<DbContextLoggerOptions>) overload to use a custom filter for events. Use the LogTo(Func<EventId,LogLevel,Boolean>, Action<EventData>) overload to log to a fully custom logger.

See Using DbContextOptions and Logging for more information and examples.

Applies to

LogTo(Func<EventId,LogLevel,Boolean>, Action<EventData>)

Logs events to a custom logger delegate filtered by a custom filter delegate. The filter should return true to log a message, or false to filter it out of the log.

public virtual Microsoft.EntityFrameworkCore.DbContextOptionsBuilder LogTo (Func<Microsoft.Extensions.Logging.EventId,Microsoft.Extensions.Logging.LogLevel,bool> filter, Action<Microsoft.EntityFrameworkCore.Diagnostics.EventData> logger);
abstract member LogTo : Func<Microsoft.Extensions.Logging.EventId, Microsoft.Extensions.Logging.LogLevel, bool> * Action<Microsoft.EntityFrameworkCore.Diagnostics.EventData> -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
override this.LogTo : Func<Microsoft.Extensions.Logging.EventId, Microsoft.Extensions.Logging.LogLevel, bool> * Action<Microsoft.EntityFrameworkCore.Diagnostics.EventData> -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
Public Overridable Function LogTo (filter As Func(Of EventId, LogLevel, Boolean), logger As Action(Of EventData)) As DbContextOptionsBuilder

Parameters

filter
Func<EventId,LogLevel,Boolean>

Delegate that returns true to log the message or false to ignore it.

logger
Action<EventData>

Delegate called when there is a message to log.

Returns

The same builder instance so that multiple calls can be chained.

Remarks

Use the LogTo(Action<String>, LogLevel, Nullable<DbContextLoggerOptions>) overload for default logging of all events. Use the LogTo(Action<String>, IEnumerable<EventId>, LogLevel, Nullable<DbContextLoggerOptions>) Use the LogTo(Action<String>, IEnumerable<String>, LogLevel, Nullable<DbContextLoggerOptions>) overload to log only events in specific categories. Use the LogTo(Action<String>, Func<EventId,LogLevel,Boolean>, Nullable<DbContextLoggerOptions>) overload to use a custom filter for events.

See Using DbContextOptions and Logging for more information and examples.

Applies to

LogTo(Action<String>, Func<EventId,LogLevel,Boolean>, Nullable<DbContextLoggerOptions>)

Logs events filtered by a supplied custom filter delegate. The filter should return true to log a message, or false to filter it out of the log.

public virtual Microsoft.EntityFrameworkCore.DbContextOptionsBuilder LogTo (Action<string> action, Func<Microsoft.Extensions.Logging.EventId,Microsoft.Extensions.Logging.LogLevel,bool> filter, Microsoft.EntityFrameworkCore.Diagnostics.DbContextLoggerOptions? options = default);
abstract member LogTo : Action<string> * Func<Microsoft.Extensions.Logging.EventId, Microsoft.Extensions.Logging.LogLevel, bool> * Nullable<Microsoft.EntityFrameworkCore.Diagnostics.DbContextLoggerOptions> -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
override this.LogTo : Action<string> * Func<Microsoft.Extensions.Logging.EventId, Microsoft.Extensions.Logging.LogLevel, bool> * Nullable<Microsoft.EntityFrameworkCore.Diagnostics.DbContextLoggerOptions> -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
Public Overridable Function LogTo (action As Action(Of String), filter As Func(Of EventId, LogLevel, Boolean), Optional options As Nullable(Of DbContextLoggerOptions) = Nothing) As DbContextOptionsBuilder

Parameters

action
Action<String>

Delegate called when there is a message to log.

filter
Func<EventId,LogLevel,Boolean>

Delegate that returns true to log the message or false to ignore it.

options
Nullable<DbContextLoggerOptions>

Formatting options for log messages. Passing null (the default) means use DefaultWithLocalTime

Returns

The same builder instance so that multiple calls can be chained.

Remarks

Use the LogTo(Action<String>, LogLevel, Nullable<DbContextLoggerOptions>) overload for default logging of all events. Use the LogTo(Action<String>, IEnumerable<EventId>, LogLevel, Nullable<DbContextLoggerOptions>) Use the LogTo(Action<String>, IEnumerable<String>, LogLevel, Nullable<DbContextLoggerOptions>) overload to log only events in specific categories. Use the LogTo(Func<EventId,LogLevel,Boolean>, Action<EventData>) overload to log to a fully custom logger.

See Using DbContextOptions and Logging for more information and examples.

Applies to