void IDbTransactionInterceptor.OnCommitted(ITransaction transaction, AddonInvoker invoker) { if (ShouldLog(LogCategory.TransactionCommitted)) { WriteTransactionCommitted(transaction, invoker); } }
void IDbTransactionInterceptor.OnRolledBack(ITransaction transaction, AddonInvoker invoker) { if (ShouldLog(LogCategory.TransactionRolledBack)) { WriteTransactionRolledBack(transaction, invoker); } }
/// <summary> /// Writes logging message for command executing. /// </summary> /// <param name="command">The command.</param> /// <param name="invoker">The invoker.</param> protected virtual void WriteCommandExecuting(TCommand command, AddonInvoker invoker) { Debug.Assert(ShouldLog(LogCategory.CommandExecuting)); Write(LogCategory.CommandExecuting, Environment.NewLine); LogCommand(command); Write(LogCategory.CommandExecuting, invoker.IsAsync ? DiagnosticMessages.DbLogger_CommandExecutingAsync(DateTimeOffset.Now) : DiagnosticMessages.DbLogger_CommandExecuting(DateTimeOffset.Now)); Write(LogCategory.CommandExecuting, Environment.NewLine); }
private void LogCommandExecuting(TCommand command, AddonInvoker invoker) { if (ShouldLog(LogCategory.CommandExecuting)) { WriteCommandExecuting(command, invoker); } else { LogCommand(command); } }
/// <summary> /// Writes logging message for connection closed. /// </summary> /// <param name="connection">The connection.</param> /// <param name="invoker">The invoker.</param> protected virtual void WriteConnectionClosed(TConnection connection, AddonInvoker invoker) { Debug.Assert(ShouldLog(LogCategory.ConnectionClosed)); if (invoker.Exception != null) { Write(LogCategory.ConnectionClosed, DiagnosticMessages.DbLogger_ConnectionCloseError(DateTimeOffset.Now, invoker.Exception.Message)); } else { Write(LogCategory.ConnectionClosed, DiagnosticMessages.DbLogger_ConnectionClosed(DateTimeOffset.Now)); } Write(LogCategory.ConnectionClosed, Environment.NewLine); }
/// <summary> /// Writes logging message for connection opened. /// </summary> /// <param name="connection">The connection.</param> /// <param name="invoker">The invoker.</param> protected virtual void WriteConnectionOpened(TConnection connection, AddonInvoker invoker) { Debug.Assert(ShouldLog(LogCategory.ConnectionOpened)); if (invoker.Exception != null) { Write(LogCategory.ConnectionOpened, invoker.IsAsync ? DiagnosticMessages.DbLogger_ConnectionOpenErrorAsync(DateTimeOffset.Now, invoker.Exception.Message) : DiagnosticMessages.DbLogger_ConnectionOpenError(DateTimeOffset.Now, invoker.Exception.Message)); } else if (invoker.TaskStatus.HasFlag(TaskStatus.Canceled)) { Write(LogCategory.ConnectionOpened, DiagnosticMessages.DbLogger_ConnectionOpenCanceled(DateTimeOffset.Now)); } else { Write(LogCategory.ConnectionOpened, invoker.IsAsync ? DiagnosticMessages.DbLogger_ConnectionOpenAsync(DateTimeOffset.Now) : DiagnosticMessages.DbLogger_ConnectionOpen(DateTimeOffset.Now)); } Write(LogCategory.ConnectionOpened, Environment.NewLine); }
private void OnCommandExecuted <TResult>(TCommand command, TResult result, AddonInvoker invoker) { if (ShouldLog(LogCategory.CommandExecuted)) { WriteCommandExecuted(command, result, invoker); } }
/// <summary> /// Writes logging message for transaction began. /// </summary> /// <param name="isolationLevel">The transaction isolation level.</param> /// <param name="name">The name of the transaction.</param> /// <param name="invoker">The invoker.</param> protected virtual void WriteTransactionBegan(IsolationLevel?isolationLevel, string name, AddonInvoker invoker) { Debug.Assert(ShouldLog(LogCategory.TransactionBegan)); if (invoker.Exception != null) { Write(LogCategory.TransactionBegan, DiagnosticMessages.DbLogger_TransactionStartError(isolationLevel, name, DateTimeOffset.Now, invoker.Exception.Message)); } else { Write(LogCategory.TransactionBegan, DiagnosticMessages.DbLogger_TransactionStarted(isolationLevel, name, DateTimeOffset.Now)); } Write(LogCategory.TransactionBegan, Environment.NewLine); }
void IDbTransactionInterceptor.OnBegan(IsolationLevel?isolationLevel, string name, AddonInvoker invoker) { if (ShouldLog(LogCategory.TransactionBegan)) { WriteTransactionBegan(isolationLevel, name, invoker); } }
void IDbConnectionInterceptor <TConnection> .OnClosed(TConnection connection, AddonInvoker invoker) { if (ShouldLog(LogCategory.ConnectionClosed)) { WriteConnectionClosed(connection, invoker); } }
void IDbConnectionInterceptor <TConnection> .OnOpening(TConnection connection, AddonInvoker invoker) { if (ShouldLog(LogCategory.ConnectionOpening)) { WriteConnectionOpening(connection, invoker); } }
void IDbNonQueryInterceptor <TCommand> .OnExecuted(TCommand command, int result, AddonInvoker invoker) { OnExecuted(command, result, invoker); }
void IDbNonQueryInterceptor <TCommand> .OnExecuting(TCommand command, AddonInvoker invoker) { OnExecuting(command, invoker); }
void IDbReaderInterceptor <TCommand, TReader> .OnExecuted(Model model, TCommand command, TReader result, AddonInvoker invoker) { OnExecuted(command, result, invoker); }
void IDbReaderInterceptor <TCommand, TReader> .OnExecuting(Model model, TCommand command, AddonInvoker invoker) { OnExecuting(command, invoker); }
/// <summary> /// Writes logging message for transaction beginning. /// </summary> /// <param name="isolationLevel">The transaction isolation level.</param> /// <param name="name">The name of the transaction.</param> /// <param name="invoker">The invoker.</param> /// <remarks>The default implementation does nothing.</remarks> protected virtual void WriteTransactionBeginning(IsolationLevel?isolationLevel, string name, AddonInvoker invoker) { Debug.Assert(ShouldLog(LogCategory.TransactionBeginning)); }
private void OnExecuted <TResult>(TCommand command, TResult result, AddonInvoker invoker) { Stopwatch.Stop(); OnCommandExecuted(command, result, invoker); }
/// <summary> /// Writes logging message for transaction committing. /// </summary> /// <param name="transaction">The transation.</param> /// <param name="invoker">The invoker.</param> /// <remarks>The default implementation does nothing.</remarks> protected virtual void WriteTransactionCommitting(ITransaction transaction, AddonInvoker invoker) { Debug.Assert(ShouldLog(LogCategory.TransactionCommitting)); }
/// <summary> /// Writes logging message for transaction rolling back. /// </summary> /// <param name="transaction">The transation.</param> /// <param name="invoker">The invoker.</param> /// <remarks>The default implementation does nothing.</remarks> protected virtual void WriteTransactionRollingBack(ITransaction transaction, AddonInvoker invoker) { Debug.Assert(ShouldLog(LogCategory.TransactionRollingBack)); }
private void OnExecuting(TCommand command, AddonInvoker invoker) { LogCommandExecuting(command, invoker); Stopwatch.Restart(); }
/// <summary> /// Writes logging message for transaction rolled back. /// </summary> /// <param name="transaction">The transation.</param> /// <param name="invoker">The invoker.</param> protected virtual void WriteTransactionRolledBack(ITransaction transaction, AddonInvoker invoker) { Debug.Assert(ShouldLog(LogCategory.TransactionRolledBack)); if (invoker.Exception != null) { Write(LogCategory.TransactionRolledBack, DiagnosticMessages.DbLogger_TransactionRollbackError(transaction.Name, transaction.Level, DateTimeOffset.Now, invoker.Exception.Message)); } else { Write(LogCategory.TransactionRolledBack, DiagnosticMessages.DbLogger_TransactionRolledBack(transaction.Name, transaction.Level, DateTimeOffset.Now)); } Write(LogCategory.TransactionRolledBack, Environment.NewLine); }
/// <summary> /// Writes logging message for connection closing. /// </summary> /// <param name="connection">The connection.</param> /// <param name="invoker">The invoker.</param> /// <remarks>The default implementation does nothing.</remarks> protected virtual void WriteConnectionClosing(TConnection connection, AddonInvoker invoker) { Debug.Assert(ShouldLog(LogCategory.ConnectionClosing)); }
/// <summary> /// Writes logging message for command executed. /// </summary> /// <typeparam name="TResult">Type of the command result.</typeparam> /// <param name="command">The command.</param> /// <param name="result">The command result.</param> /// <param name="invoker">The invoker.</param> protected virtual void WriteCommandExecuted <TResult>(TCommand command, TResult result, AddonInvoker invoker) { Debug.Assert(ShouldLog(LogCategory.CommandExecuted)); var exception = invoker.Exception; if (exception != null) { Write(LogCategory.CommandExecuted, DiagnosticMessages.DbLogger_CommandFailed(Stopwatch.ElapsedMilliseconds, exception.Message)); } else if (invoker.TaskStatus.HasFlag(TaskStatus.Canceled)) { Write(LogCategory.CommandExecuted, DiagnosticMessages.DbLogger_CommandCanceled(Stopwatch.ElapsedMilliseconds)); } else { var resultString = (object)result == null ? "null" : (result is DbReader) ? result.GetType().Name : result.ToString(); Write(LogCategory.CommandExecuted, DiagnosticMessages.DbLogger_CommandComplete(Stopwatch.ElapsedMilliseconds, resultString)); } Write(LogCategory.CommandExecuted, Environment.NewLine); Write(LogCategory.CommandExecuted, Environment.NewLine); }