Share via


DatabaseLogFormatter Class

Definition

This is the default log formatter used when some Action<T> is set onto the Log property. A different formatter can be used by creating a class that inherits from this class and overrides some or all methods to change behavior.

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
Inheritance
DatabaseLogFormatter
Implements

Remarks

To set the new formatter create a code-based configuration for EF using DbConfiguration and then set the formatter class to use with SetDatabaseLogFormatter(Func<DbContext,Action<String>,DatabaseLogFormatter>). Note that setting the type of formatter to use with this method does change the way command are logged when Log is used. It is still necessary to set a Action<T> onto Log before any commands will be logged. For more low-level control over logging/interception see IDbCommandInterceptor and DbInterception. Interceptors can also be registered in the config file of the application. See http://go.microsoft.com/fwlink/?LinkId=260883 for more information about Entity Framework configuration.

Constructors

DatabaseLogFormatter(Action<String>)

Creates a formatter that will not filter by any DbContext and will instead log every command from any context and also commands that do not originate from a context.

DatabaseLogFormatter(DbContext, Action<String>)

Creates a formatter that will only log commands the come from the given DbContext instance.

Properties

Context

The context for which commands are being logged, or null if commands from all contexts are being logged.

Stopwatch
Obsolete.

This property is obsolete. Using it can result in logging incorrect execution times. Call GetStopwatch(DbCommandInterceptionContext) instead.

Methods

BeganTransaction(DbConnection, BeginTransactionInterceptionContext)

Called after BeginTransaction(IsolationLevel) is invoked. The default implementation of this method filters by DbContext set into Context, if any, and then logs the event.

BeginningTransaction(DbConnection, BeginTransactionInterceptionContext)

Does not write to log unless overridden.

Closed(DbConnection, DbConnectionInterceptionContext)

Called after Close() is invoked. The default implementation of this method filters by DbContext set into Context, if any, and then logs the event.

Closing(DbConnection, DbConnectionInterceptionContext)

Does not write to log unless overridden.

Committed(DbTransaction, DbTransactionInterceptionContext)

This method is called after Commit() is invoked. The default implementation of this method filters by DbContext set into Context, if any, and then logs the event.

Committing(DbTransaction, DbTransactionInterceptionContext)

Does not write to log unless overridden.

ConnectionGetting(DbTransaction, DbTransactionInterceptionContext<DbConnection>)

Does not write to log unless overridden.

ConnectionGot(DbTransaction, DbTransactionInterceptionContext<DbConnection>)

Does not write to log unless overridden.

ConnectionStringGetting(DbConnection, DbConnectionInterceptionContext<String>)

Does not write to log unless overridden.

ConnectionStringGot(DbConnection, DbConnectionInterceptionContext<String>)

Does not write to log unless overridden.

ConnectionStringSet(DbConnection, DbConnectionPropertyInterceptionContext<String>)

Does not write to log unless overridden.

ConnectionStringSetting(DbConnection, DbConnectionPropertyInterceptionContext<String>)

Does not write to log unless overridden.

ConnectionTimeoutGetting(DbConnection, DbConnectionInterceptionContext<Int32>)

Does not write to log unless overridden.

ConnectionTimeoutGot(DbConnection, DbConnectionInterceptionContext<Int32>)

Does not write to log unless overridden.

DatabaseGetting(DbConnection, DbConnectionInterceptionContext<String>)

Does not write to log unless overridden.

DatabaseGot(DbConnection, DbConnectionInterceptionContext<String>)

Does not write to log unless overridden.

DataSourceGetting(DbConnection, DbConnectionInterceptionContext<String>)

Does not write to log unless overridden.

DataSourceGot(DbConnection, DbConnectionInterceptionContext<String>)

Does not write to log unless overridden.

Disposed(DbConnection, DbConnectionInterceptionContext)

Does not write to log unless overridden.

Disposed(DbTransaction, DbTransactionInterceptionContext)

Does not write to log unless overridden.

Disposing(DbConnection, DbConnectionInterceptionContext)

Called before Dispose() is invoked. The default implementation of this method filters by DbContext set into Context, if any, and then logs the event.

Disposing(DbTransaction, DbTransactionInterceptionContext)

This method is called before Dispose() is invoked. The default implementation of this method filters by DbContext set into Context, if any, and then logs the event.

EnlistedTransaction(DbConnection, EnlistTransactionInterceptionContext)

Does not write to log unless overridden.

EnlistingTransaction(DbConnection, EnlistTransactionInterceptionContext)

Does not write to log unless overridden.

Equals(Object)

Determines whether the specified object is equal to the current object.

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

Called whenever a command has completed executing. The default implementation of this method filters by DbContext set into Context, if any, and then calls LogResult<TResult>(DbCommand, DbCommandInterceptionContext<TResult>). This method would typically only be overridden to change the context filtering behavior.

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

Called whenever a command is about to be executed. The default implementation of this method filters by DbContext set into Context, if any, and then calls LogCommand<TResult>(DbCommand, DbCommandInterceptionContext<TResult>). This method would typically only be overridden to change the context filtering behavior.

GetHashCode()

Serves as the default hash function.

GetStopwatch(DbCommandInterceptionContext)

The stopwatch used to time executions. This stopwatch is started at the end of NonQueryExecuting(DbCommand, DbCommandInterceptionContext<Int32>), ScalarExecuting(DbCommand, DbCommandInterceptionContext<Object>), and ReaderExecuting(DbCommand, DbCommandInterceptionContext<DbDataReader>) methods and is stopped at the beginning of the NonQueryExecuted(DbCommand, DbCommandInterceptionContext<Int32>), ScalarExecuted(DbCommand, DbCommandInterceptionContext<Object>), and ReaderExecuted(DbCommand, DbCommandInterceptionContext<DbDataReader>) methods. If these methods are overridden and the stopwatch is being used then the overrides should either call the base method or start/stop the stopwatch themselves.

GetType()

Gets the Type of the current instance.

IsolationLevelGetting(DbTransaction, DbTransactionInterceptionContext<IsolationLevel>)

Does not write to log unless overridden.

IsolationLevelGot(DbTransaction, DbTransactionInterceptionContext<IsolationLevel>)

Does not write to log unless overridden.

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

Called to log a command that is about to be executed. Override this method to change how the command is logged to System.Data.Entity.Infrastructure.Interception.DatabaseLogFormatter.WriteAction.

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

Called by LogCommand<TResult>(DbCommand, DbCommandInterceptionContext<TResult>) to log each parameter. This method can be called from an overridden implementation of LogCommand<TResult>(DbCommand, DbCommandInterceptionContext<TResult>) to log parameters, and/or can be overridden to change the way that parameters are logged to System.Data.Entity.Infrastructure.Interception.DatabaseLogFormatter.WriteAction.

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

Called to log the result of executing a command. Override this method to change how results are logged to System.Data.Entity.Infrastructure.Interception.DatabaseLogFormatter.WriteAction.

NonQueryExecuted(DbCommand, DbCommandInterceptionContext<Int32>)

This method is called after a call to ExecuteNonQuery() or one of its async counterparts is made. The default implementation stopsthe stopwatch returned from GetStopwatch(DbCommandInterceptionContext) and calls Executed<TResult>(DbCommand, DbCommandInterceptionContext<TResult>).

NonQueryExecuting(DbCommand, DbCommandInterceptionContext<Int32>)

This method is called before a call to ExecuteNonQuery() or one of its async counterparts is made. The default implementation calls Executing<TResult>(DbCommand, DbCommandInterceptionContext<TResult>) and starts the stopwatch returned from GetStopwatch(DbCommandInterceptionContext).

Opened(DbConnection, DbConnectionInterceptionContext)

Called after Open() or its async counterpart is invoked. The default implementation of this method filters by DbContext set into Context, if any, and then logs the event.

Opening(DbConnection, DbConnectionInterceptionContext)

Does not write to log unless overridden.

ReaderExecuted(DbCommand, DbCommandInterceptionContext<DbDataReader>)

This method is called after a call to ExecuteReader(CommandBehavior) or one of its async counterparts is made. The default implementation stopsthe stopwatch returned from GetStopwatch(DbCommandInterceptionContext) and calls Executed<TResult>(DbCommand, DbCommandInterceptionContext<TResult>).

ReaderExecuting(DbCommand, DbCommandInterceptionContext<DbDataReader>)

This method is called before a call to ExecuteReader(CommandBehavior) or one of its async counterparts is made. The default implementation calls Executing<TResult>(DbCommand, DbCommandInterceptionContext<TResult>) and starts the stopwatch returned from GetStopwatch(DbCommandInterceptionContext).

RolledBack(DbTransaction, DbTransactionInterceptionContext)

This method is called after Rollback() is invoked. The default implementation of this method filters by DbContext set into Context, if any, and then logs the event.

RollingBack(DbTransaction, DbTransactionInterceptionContext)

Does not write to log unless overridden.

ScalarExecuted(DbCommand, DbCommandInterceptionContext<Object>)

This method is called after a call to ExecuteScalar() or one of its async counterparts is made. The default implementation stopsthe stopwatch returned from GetStopwatch(DbCommandInterceptionContext) and calls Executed<TResult>(DbCommand, DbCommandInterceptionContext<TResult>).

ScalarExecuting(DbCommand, DbCommandInterceptionContext<Object>)

This method is called before a call to ExecuteScalar() or one of its async counterparts is made. The default implementation calls Executing<TResult>(DbCommand, DbCommandInterceptionContext<TResult>) and starts the stopwatch returned from GetStopwatch(DbCommandInterceptionContext).

ServerVersionGetting(DbConnection, DbConnectionInterceptionContext<String>)

Does not write to log unless overridden.

ServerVersionGot(DbConnection, DbConnectionInterceptionContext<String>)

Does not write to log unless overridden.

StateGetting(DbConnection, DbConnectionInterceptionContext<ConnectionState>)

Does not write to log unless overridden.

StateGot(DbConnection, DbConnectionInterceptionContext<ConnectionState>)

Does not write to log unless overridden.

ToString()

Returns a string that represents the current object.

Write(String)

Writes the given string to the underlying write delegate.

Applies to