DbContextOptionsBuilder.LogTo Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
LogTo(Action<String>, IEnumerable<String>, LogLevel, Nullable<DbContextLoggerOptions>) |
Logs all events in the specified categories using the supplied action. For example, use
|
LogTo(Action<String>, IEnumerable<EventId>, LogLevel, Nullable<DbContextLoggerOptions>) |
Logs the specified events using the supplied action. For example, use
|
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>, LogLevel, Nullable<DbContextLoggerOptions>) |
Logs using the supplied action. For example, use |
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>, IEnumerable<String>, LogLevel, Nullable<DbContextLoggerOptions>)
- Source:
- DbContextOptionsBuilder.cs
- Source:
- DbContextOptionsBuilder.cs
- Source:
- DbContextOptionsBuilder.cs
- Source:
- DbContextOptionsBuilder.cs
- Source:
- DbContextOptionsBuilder.cs
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
- categories
- IEnumerable<String>
The DbLoggerCategory of each event to log.
- 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>)
- Source:
- DbContextOptionsBuilder.cs
- Source:
- DbContextOptionsBuilder.cs
- Source:
- DbContextOptionsBuilder.cs
- Source:
- DbContextOptionsBuilder.cs
- Source:
- DbContextOptionsBuilder.cs
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
- events
- IEnumerable<EventId>
The EventId of each event to log.
- 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>, Func<EventId,LogLevel,Boolean>, Nullable<DbContextLoggerOptions>)
- Source:
- DbContextOptionsBuilder.cs
- Source:
- DbContextOptionsBuilder.cs
- Source:
- DbContextOptionsBuilder.cs
- Source:
- DbContextOptionsBuilder.cs
- Source:
- DbContextOptionsBuilder.cs
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
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
LogTo(Action<String>, LogLevel, Nullable<DbContextLoggerOptions>)
- Source:
- DbContextOptionsBuilder.cs
- Source:
- DbContextOptionsBuilder.cs
- Source:
- DbContextOptionsBuilder.cs
- Source:
- DbContextOptionsBuilder.cs
- Source:
- DbContextOptionsBuilder.cs
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
- 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>)
- Source:
- DbContextOptionsBuilder.cs
- Source:
- DbContextOptionsBuilder.cs
- Source:
- DbContextOptionsBuilder.cs
- Source:
- DbContextOptionsBuilder.cs
- Source:
- DbContextOptionsBuilder.cs
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
Delegate that returns true to log the message or false to ignore it.
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
Entity Framework