语言

DatabaseLogFormatter 类

定义

这是在将某些 Action<T> 格式化程序设置为 Log 属性时使用的默认日志格式化程序。 通过创建继承自此类的类并重写某些或所有方法来更改行为,可以使用其他格式化程序。

public class DatabaseLogFormatter : System.Data.Entity.Infrastructure.Interception.IDbCommandInterceptor, System.Data.Entity.Infrastructure.Interception.IDbConnectionInterceptor, System.Data.Entity.Infrastructure.Interception.IDbTransactionInterceptor
type DatabaseLogFormatter = class
    interface IDbCommandInterceptor
    interface IDbConnectionInterceptor
    interface IDbTransactionInterceptor
    interface IDbInterceptor
Public Class DatabaseLogFormatter
Implements IDbCommandInterceptor, IDbConnectionInterceptor, IDbTransactionInterceptor
继承
DatabaseLogFormatter
实现

注解

若要设置新的格式化程序,请使用 EF DbConfiguration 创建基于代码的配置,然后将格式化程序类设置为与它一起使用 SetDatabaseLogFormatter(Func<DbContext,Action<String>,DatabaseLogFormatter>)。 请注意,设置与此方法一起使用的格式化程序类型会更改使用时 Log 记录命令的方式。 在记录任何命令之前,仍需将其设置为 Action<T> on Log 。 有关日志记录/拦截的低级别控制,请参阅 IDbCommandInterceptor 和 DbInterception。 还可以在应用程序的配置文件中注册侦听器。 有关 Entity Framework 配置的详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkId=260883 。

构造函数

名称 说明
DatabaseLogFormatter(Action<String>)

创建一个格式化程序,该格式化程序不会按任何 DbContext 筛选,而是从任何上下文记录每个命令,以及不源自上下文的命令。

DatabaseLogFormatter(DbContext, Action<String>)

创建一个格式化程序,该格式化程序将只记录来自给定 DbContext 实例的命令。

属性

名称 说明
Context

要记录其命令的上下文;如果记录来自所有上下文的命令,则为 null。

Stopwatch
已过时.

此属性已过时。 使用它可能会导致记录不正确的执行时间。 请改为调用 GetStopwatch(DbCommandInterceptionContext) 。

方法

名称 说明
BeganTransaction(DbConnection, BeginTransactionInterceptionContext)

调用后 BeginTransaction(IsolationLevel) 调用。 此方法的默认实现通过 DbContext 设置为 Context(如果有)筛选,然后记录事件。

BeginningTransaction(DbConnection, BeginTransactionInterceptionContext)

除非重写,否则不会写入日志。

Closed(DbConnection, DbConnectionInterceptionContext)

调用后 Close() 调用。 此方法的默认实现通过 DbContext 设置为 Context(如果有)筛选,然后记录事件。

Closing(DbConnection, DbConnectionInterceptionContext)

除非重写,否则不会写入日志。

Committed(DbTransaction, DbTransactionInterceptionContext)

调用后 Commit() 调用此方法。 此方法的默认实现通过 DbContext 设置为 Context(如果有)筛选,然后记录事件。

Committing(DbTransaction, DbTransactionInterceptionContext)

除非重写,否则不会写入日志。

ConnectionGetting(DbTransaction, DbTransactionInterceptionContext<DbConnection>)

除非重写,否则不会写入日志。

ConnectionGot(DbTransaction, DbTransactionInterceptionContext<DbConnection>)

除非重写,否则不会写入日志。

ConnectionStringGetting(DbConnection, DbConnectionInterceptionContext<String>)

除非重写,否则不会写入日志。

ConnectionStringGot(DbConnection, DbConnectionInterceptionContext<String>)

除非重写,否则不会写入日志。

ConnectionStringSet(DbConnection, DbConnectionPropertyInterceptionContext<String>)

除非重写,否则不会写入日志。

ConnectionStringSetting(DbConnection, DbConnectionPropertyInterceptionContext<String>)

除非重写,否则不会写入日志。

ConnectionTimeoutGetting(DbConnection, DbConnectionInterceptionContext<Int32>)

除非重写,否则不会写入日志。

ConnectionTimeoutGot(DbConnection, DbConnectionInterceptionContext<Int32>)

除非重写,否则不会写入日志。

DatabaseGetting(DbConnection, DbConnectionInterceptionContext<String>)

除非重写,否则不会写入日志。

DatabaseGot(DbConnection, DbConnectionInterceptionContext<String>)

除非重写,否则不会写入日志。

DataSourceGetting(DbConnection, DbConnectionInterceptionContext<String>)

除非重写,否则不会写入日志。

DataSourceGot(DbConnection, DbConnectionInterceptionContext<String>)

除非重写,否则不会写入日志。

Disposed(DbConnection, DbConnectionInterceptionContext)

除非重写,否则不会写入日志。

Disposed(DbTransaction, DbTransactionInterceptionContext)

除非重写,否则不会写入日志。

Disposing(DbConnection, DbConnectionInterceptionContext)

调用之前 Dispose() 调用。 此方法的默认实现通过 DbContext 设置为 Context(如果有)筛选,然后记录事件。

Disposing(DbTransaction, DbTransactionInterceptionContext)

在调用之前 Dispose() 调用此方法。 此方法的默认实现通过 DbContext 设置为 Context(如果有)筛选,然后记录事件。

EnlistedTransaction(DbConnection, EnlistTransactionInterceptionContext)

除非重写,否则不会写入日志。

EnlistingTransaction(DbConnection, EnlistTransactionInterceptionContext)

除非重写,否则不会写入日志。

Equals(Object)

这是在将某些 Action<T> 格式化程序设置为 Log 属性时使用的默认日志格式化程序。 通过创建继承自此类的类并重写某些或所有方法来更改行为,可以使用其他格式化程序。

Executed<TResult>(DbCommand, DbCommandInterceptionContext<TResult>)

每当命令完成执行时调用。 此方法的默认实现通过 DbContext 设置为 Context(如果有)筛选,然后调用 LogResult<TResult>(DbCommand, DbCommandInterceptionContext<TResult>)。 此方法通常只能重写以更改上下文筛选行为。

Executing<TResult>(DbCommand, DbCommandInterceptionContext<TResult>)

每当命令即将执行时调用。 此方法的默认实现通过 DbContext 设置为 Context(如果有)筛选,然后调用 LogCommand<TResult>(DbCommand, DbCommandInterceptionContext<TResult>)。 此方法通常只能重写以更改上下文筛选行为。

GetHashCode()

这是在将某些 Action<T> 格式化程序设置为 Log 属性时使用的默认日志格式化程序。 通过创建继承自此类的类并重写某些或所有方法来更改行为,可以使用其他格式化程序。

GetStopwatch(DbCommandInterceptionContext)

用于时间执行的秒表。 此秒表在结尾NonQueryExecuting(DbCommand, DbCommandInterceptionContext<Int32>)处启动,ScalarExecuting(DbCommand, DbCommandInterceptionContext<Object>)方法ReaderExecuting(DbCommand, DbCommandInterceptionContext<DbDataReader>)在开头和方法处NonQueryExecuted(DbCommand, DbCommandInterceptionContext<Int32>)ScalarExecuted(DbCommand, DbCommandInterceptionContext<Object>)ReaderExecuted(DbCommand, DbCommandInterceptionContext<DbDataReader>)停止。 如果重写了这些方法,并且正在使用秒表,则替代应调用基方法或启动/停止秒表本身。

GetType()

这是在将某些 Action<T> 格式化程序设置为 Log 属性时使用的默认日志格式化程序。 通过创建继承自此类的类并重写某些或所有方法来更改行为,可以使用其他格式化程序。

IsolationLevelGetting(DbTransaction, DbTransactionInterceptionContext<IsolationLevel>)

除非重写,否则不会写入日志。

IsolationLevelGot(DbTransaction, DbTransactionInterceptionContext<IsolationLevel>)

除非重写,否则不会写入日志。

LogCommand<TResult>(DbCommand, DbCommandInterceptionContext<TResult>)

调用以记录即将执行的命令。 重写此方法以更改命令的记录方式 System.Data.Entity.Infrastructure.Interception.DatabaseLogFormatter.WriteAction。

LogParameter<TResult>(DbCommand, DbCommandInterceptionContext<TResult>, DbParameter)

调用者 LogCommand<TResult>(DbCommand, DbCommandInterceptionContext<TResult>) 以记录每个参数。 可以从重写的对日志参数实现 LogCommand<TResult>(DbCommand, DbCommandInterceptionContext<TResult>) 调用此方法,并且/或可以重写以更改参数的记录 System.Data.Entity.Infrastructure.Interception.DatabaseLogFormatter.WriteAction方式。

LogResult<TResult>(DbCommand, DbCommandInterceptionContext<TResult>)

调用以记录执行命令的结果。 重写此方法以更改结果记录到 System.Data.Entity.Infrastructure.Interception.DatabaseLogFormatter.WriteAction的方式。

NonQueryExecuted(DbCommand, DbCommandInterceptionContext<Int32>)

调用或其异步对应项之一后调用 ExecuteNonQuery() 此方法。 默认实现停止从 GetStopwatch(DbCommandInterceptionContext) 中返回的秒表和调用 Executed<TResult>(DbCommand, DbCommandInterceptionContext<TResult>)。

NonQueryExecuting(DbCommand, DbCommandInterceptionContext<Int32>)

在调用或调用某个异步对应项之前调用 ExecuteNonQuery() 此方法。 默认实现调用 Executing<TResult>(DbCommand, DbCommandInterceptionContext<TResult>) 并启动从中 GetStopwatch(DbCommandInterceptionContext)返回的秒表。

Opened(DbConnection, DbConnectionInterceptionContext)

调用后 Open() 或其异步对应项。 此方法的默认实现通过 DbContext 设置为 Context(如果有)筛选,然后记录事件。

Opening(DbConnection, DbConnectionInterceptionContext)

除非重写,否则不会写入日志。

ReaderExecuted(DbCommand, DbCommandInterceptionContext<DbDataReader>)

调用或其异步对应项之一后调用 ExecuteReader(CommandBehavior) 此方法。 默认实现停止从 GetStopwatch(DbCommandInterceptionContext) 中返回的秒表和调用 Executed<TResult>(DbCommand, DbCommandInterceptionContext<TResult>)。

ReaderExecuting(DbCommand, DbCommandInterceptionContext<DbDataReader>)

在调用或调用某个异步对应项之前调用 ExecuteReader(CommandBehavior) 此方法。 默认实现调用 Executing<TResult>(DbCommand, DbCommandInterceptionContext<TResult>) 并启动从中 GetStopwatch(DbCommandInterceptionContext)返回的秒表。

RolledBack(DbTransaction, DbTransactionInterceptionContext)

调用后 Rollback() 调用此方法。 此方法的默认实现通过 DbContext 设置为 Context(如果有)筛选,然后记录事件。

RollingBack(DbTransaction, DbTransactionInterceptionContext)

除非重写,否则不会写入日志。

ScalarExecuted(DbCommand, DbCommandInterceptionContext<Object>)

调用或其异步对应项之一后调用 ExecuteScalar() 此方法。 默认实现停止从 GetStopwatch(DbCommandInterceptionContext) 中返回的秒表和调用 Executed<TResult>(DbCommand, DbCommandInterceptionContext<TResult>)。

ScalarExecuting(DbCommand, DbCommandInterceptionContext<Object>)

在调用或调用某个异步对应项之前调用 ExecuteScalar() 此方法。 默认实现调用 Executing<TResult>(DbCommand, DbCommandInterceptionContext<TResult>) 并启动从中 GetStopwatch(DbCommandInterceptionContext)返回的秒表。

ServerVersionGetting(DbConnection, DbConnectionInterceptionContext<String>)

除非重写,否则不会写入日志。

ServerVersionGot(DbConnection, DbConnectionInterceptionContext<String>)

除非重写,否则不会写入日志。

StateGetting(DbConnection, DbConnectionInterceptionContext<ConnectionState>)

除非重写,否则不会写入日志。

StateGot(DbConnection, DbConnectionInterceptionContext<ConnectionState>)

除非重写,否则不会写入日志。

ToString()

这是在将某些 Action<T> 格式化程序设置为 Log 属性时使用的默认日志格式化程序。 通过创建继承自此类的类并重写某些或所有方法来更改行为,可以使用其他格式化程序。

Write(String)

将给定字符串写入基础写入委托。

适用于