Ejemplo n.º 1
0
        public void LogCommand(DbCommand command, DbCommandContext interceptionCommandContext)
        {
            var commandText = command.CommandText ?? "<null>";
            var commandInfo = new Command
            {
                IsAsync    = interceptionCommandContext.IsAsync,
                Sql        = commandText.Trim(),
                SqlHash    = commandText.Trim().ComputeHash(),
                StackTrace = new CallingMethod {
                    AssembliesToExclude = AssembliesToExclude
                }.GetCallingMethodInfo()
            };

            setBaseInfo(interceptionCommandContext, commandInfo);
            commandInfo.CommandId = UniqueIdExtensions <DbCommand> .GetUniqueId(command).ToInt();

            if (commandInfo.ConnectionId == null)
            {
                commandInfo.ConnectionId = UniqueIdExtensions <DbConnection> .GetUniqueId(command.Connection).ToInt();
            }

            if (command.Transaction != null)
            {
                commandInfo.TransactionId = UniqueIdExtensions <DbTransaction> .GetUniqueId(command.Transaction).ToInt();

                commandInfo.IsolationLevel = command.Transaction.IsolationLevel;
            }

            foreach (var parameter in command.Parameters.OfType <DbParameter>())
            {
                commandInfo.Parameters.Add(logParameter(parameter));
            }

            _baseInfoQueue.Enqueue(commandInfo);
        }
Ejemplo n.º 2
0
        public void LogResult(DbCommand command, DbCommandContext interceptionCommandContext)
        {
            var result       = interceptionCommandContext.Result;
            var resultString = (object)result == null
                ? "null"
                : (result is DbDataReader)
                    ? result.GetType().Name
                    : result.ToString();

            var commandResult = new CommandResult
            {
                Exception           = interceptionCommandContext.Exception != null ? interceptionCommandContext.Exception.Message : "",
                IsCanceled          = interceptionCommandContext.IsCanceled,
                ElapsedMilliseconds = interceptionCommandContext.ElapsedMilliseconds,
                ResultString        = resultString,
                StackTrace          = new CallingMethod {
                    AssembliesToExclude = AssembliesToExclude
                }.GetCallingMethodInfo(),
                FieldsCount = gefFieldsCount(result)
            };

            setBaseInfo(interceptionCommandContext, commandResult);

            commandResult.CommandId = UniqueIdExtensions <DbCommand> .GetUniqueId(command).ToInt();

            if (commandResult.ConnectionId == null)
            {
                commandResult.ConnectionId = UniqueIdExtensions <DbConnection> .GetUniqueId(command.Connection).ToInt();
            }

            if (command.Transaction != null)
            {
                commandResult.TransactionId = UniqueIdExtensions <DbTransaction> .GetUniqueId(command.Transaction).ToInt();
            }

            if (interceptionCommandContext.DataTable != null && interceptionCommandContext.DataTable.Rows != null)
            {
                commandResult.RowsReturned = interceptionCommandContext.DataTable.Rows.Count;

                foreach (DataColumn column in interceptionCommandContext.DataTable.Columns)
                {
                    commandResult.Columns.Add(new ColumnInfo
                    {
                        ColumnName = column.ColumnName,
                        DataType   = column.DataType.ToString(),
                        Ordinal    = column.Ordinal,
                        IsKey      = interceptionCommandContext.Keys != null && interceptionCommandContext.Keys.Contains(column.ColumnName)
                    });
                }
            }

            _baseInfoQueue.Enqueue(commandResult);
        }
 public static DbCommandContext GetLoggedDbCommand(DbCommand command, Exception exception)
 {
     var context = new DbCommandContext
     {
         IsAsync = false,
         IsCanceled = false,
         Exception = exception,
         ObjectContextId = SessionIdLoggingContext.SessionId.GetUniqueId(),
         ObjectContextName = SessionId,
         ConnectionId = UniqueIdExtensions<DbConnection>.GetUniqueId(command.Connection).ToInt()
     };
     return context;
 }
Ejemplo n.º 4
0
 public void ScalarExecuting(DbCommand command, DbCommandContext context)
 {
     LogCommand(command, context);
 }
Ejemplo n.º 5
0
 public void ScalarExecuted(DbCommand command, DbCommandContext context)
 {
     LogResult(command, context);
 }
Ejemplo n.º 6
0
 public void NonQueryExecuting(DbCommand command, DbCommandContext context)
 {
     LogCommand(command, context);
 }
Ejemplo n.º 7
0
 public void NonQueryExecuted(DbCommand command, DbCommandContext context)
 {
     LogResult(command, context);
 }
 public static DbCommandContext GetLoggedResult(
                         DbCommand command, Exception exception, object result,
                         long? elapsedMilliseconds, DataTable dataTable)
 {
     var context = new DbCommandContext
     {
         IsAsync = false,
         IsCanceled = false,
         Exception = exception,
         Result = result,
         ElapsedMilliseconds = elapsedMilliseconds,
         DataTable = dataTable,
         ObjectContextId = SessionIdLoggingContext.SessionId.GetUniqueId(),
         ObjectContextName = SessionId,
         ConnectionId = UniqueIdExtensions<DbConnection>.GetUniqueId(command.Connection).ToInt()
     };
     return context;
 }