Пример #1
0
 void IDbTransactionInterceptor.OnCommitted(ITransaction transaction, AddonInvoker invoker)
 {
     if (ShouldLog(LogCategory.TransactionCommitted))
     {
         WriteTransactionCommitted(transaction, invoker);
     }
 }
Пример #2
0
 void IDbTransactionInterceptor.OnRolledBack(ITransaction transaction, AddonInvoker invoker)
 {
     if (ShouldLog(LogCategory.TransactionRolledBack))
     {
         WriteTransactionRolledBack(transaction, invoker);
     }
 }
Пример #3
0
 /// <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);
 }
Пример #4
0
 private void LogCommandExecuting(TCommand command, AddonInvoker invoker)
 {
     if (ShouldLog(LogCategory.CommandExecuting))
     {
         WriteCommandExecuting(command, invoker);
     }
     else
     {
         LogCommand(command);
     }
 }
Пример #5
0
 /// <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);
 }
Пример #6
0
 /// <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);
 }
Пример #7
0
 private void OnCommandExecuted <TResult>(TCommand command, TResult result, AddonInvoker invoker)
 {
     if (ShouldLog(LogCategory.CommandExecuted))
     {
         WriteCommandExecuted(command, result, invoker);
     }
 }
Пример #8
0
 /// <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);
 }
Пример #9
0
 void IDbTransactionInterceptor.OnBegan(IsolationLevel?isolationLevel, string name, AddonInvoker invoker)
 {
     if (ShouldLog(LogCategory.TransactionBegan))
     {
         WriteTransactionBegan(isolationLevel, name, invoker);
     }
 }
Пример #10
0
 void IDbConnectionInterceptor <TConnection> .OnClosed(TConnection connection, AddonInvoker invoker)
 {
     if (ShouldLog(LogCategory.ConnectionClosed))
     {
         WriteConnectionClosed(connection, invoker);
     }
 }
Пример #11
0
 void IDbConnectionInterceptor <TConnection> .OnOpening(TConnection connection, AddonInvoker invoker)
 {
     if (ShouldLog(LogCategory.ConnectionOpening))
     {
         WriteConnectionOpening(connection, invoker);
     }
 }
Пример #12
0
 void IDbNonQueryInterceptor <TCommand> .OnExecuted(TCommand command, int result, AddonInvoker invoker)
 {
     OnExecuted(command, result, invoker);
 }
Пример #13
0
 void IDbNonQueryInterceptor <TCommand> .OnExecuting(TCommand command, AddonInvoker invoker)
 {
     OnExecuting(command, invoker);
 }
Пример #14
0
 void IDbReaderInterceptor <TCommand, TReader> .OnExecuted(Model model, TCommand command, TReader result, AddonInvoker invoker)
 {
     OnExecuted(command, result, invoker);
 }
Пример #15
0
 void IDbReaderInterceptor <TCommand, TReader> .OnExecuting(Model model, TCommand command, AddonInvoker invoker)
 {
     OnExecuting(command, invoker);
 }
Пример #16
0
 /// <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));
 }
Пример #17
0
 private void OnExecuted <TResult>(TCommand command, TResult result, AddonInvoker invoker)
 {
     Stopwatch.Stop();
     OnCommandExecuted(command, result, invoker);
 }
Пример #18
0
 /// <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));
 }
Пример #19
0
 /// <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));
 }
Пример #20
0
 private void OnExecuting(TCommand command, AddonInvoker invoker)
 {
     LogCommandExecuting(command, invoker);
     Stopwatch.Restart();
 }
Пример #21
0
 /// <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);
 }
Пример #22
0
 /// <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));
 }
Пример #23
0
            /// <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);
            }