예제 #1
0
 internal void RaiseExecuting(CommandExecutionEventArgs e)
 {
     if (this.CommandExecuting != null)
     {
         this.CommandExecuting(this, e);
     }
 }
예제 #2
0
 internal void RaiseFailed(CommandExecutionEventArgs e)
 {
     if (this.CommandFailed != null)
     {
         this.CommandFailed(this, e);
     }
 }
예제 #3
0
        /// <summary>
        /// Executes a SQL statement against a connection object.
        /// </summary>
        /// <returns>The number of rows affected.</returns>
        public override int ExecuteNonQuery()
        {
            CommandExecutionEventArgs e = new CommandExecutionEventArgs(this, "ExecuteNonQuery");

            e.Status = CommandExecutionStatus.Executing;
            Stopwatch sw = new Stopwatch();

            this.Connection.RaiseExecuting(e);
            try
            {
                sw.Start();
                int result = base.ExecuteNonQuery();
                sw.Stop();
                e.Result   = result;
                e.Duration = sw.Elapsed;
                e.Status   = CommandExecutionStatus.Finished;
                this.Connection.RaiseFinished(e);
                return(result);
            }
            catch (Exception ex)
            {
                e.Result = ex;
                e.Status = CommandExecutionStatus.Failed;
                this.Connection.RaiseFailed(e);
                throw;
            }
        }
예제 #4
0
 /// <summary>
 /// Executes a SQL statement against a connection object.
 /// </summary>
 /// <returns>The number of rows affected.</returns>
 public override int ExecuteNonQuery()
 {
     CommandExecutionEventArgs e = new CommandExecutionEventArgs(this, "ExecuteNonQuery");
     e.Status = CommandExecutionStatus.Executing;
     Stopwatch sw = new Stopwatch();
     this.Connection.RaiseExecuting(e);
     try
     {
         sw.Start();
         int result = base.ExecuteNonQuery();
         sw.Stop();
         e.Result = result;
         e.Duration = sw.Elapsed;
         e.Status = CommandExecutionStatus.Finished;
         this.Connection.RaiseFinished(e);
         return result;
     }
     catch (Exception ex)
     {
         e.Result = ex;
         e.Status = CommandExecutionStatus.Failed;
         this.Connection.RaiseFailed(e);
         throw;
     }
 }
예제 #5
0
        /// <summary>
        /// Executes the command text against the connection.
        /// </summary>
        /// <param name="behavior">An instance of <see cref="T:System.Data.CommandBehavior"/>.</param>
        /// <returns>
        /// A <see cref="T:System.Data.Common.DbDataReader"/>.
        /// </returns>
        protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
        {
            CommandExecutionEventArgs e = new CommandExecutionEventArgs(this, "ExecuteReader");

            e.Status = CommandExecutionStatus.Executing;
            this.Connection.RaiseExecuting(e);
            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                DbDataReader result = base.ExecuteDbDataReader(behavior);
                sw.Stop();
                e.Result   = result;
                e.Status   = CommandExecutionStatus.Finished;
                e.Duration = sw.Elapsed;
                this.Connection.RaiseFinished(e);
                return(result);
            }
            catch (Exception ex)
            {
                e.Result = ex;
                e.Status = CommandExecutionStatus.Failed;
                this.Connection.RaiseFailed(e);
                throw;
            }
        }
 private void AppendToLog(object sender, CommandExecutionEventArgs e)
 {
     if (this.m_log != null)
     {
         this.m_log.WriteLine(e.ToTraceString().TrimEnd());
         this.m_log.WriteLine();
     }
 }
        ///// <summary>
        ///// Initializes a new instance of the <see cref="ExtendedRaccoEcommerceEntities"/> class.
        ///// </summary>
        ///// <param name="connectionString">The connection string.</param>
        //public ExtendedRaccoEcommerceEntities(String connectionString)
        //    : base(EntityConnectionWrapperUtils.CreateEntityConnectionWithWrappers(
        //            connectionString,
        //            "EFTracingProvider",
        //            "EFCachingProvider"
        //    )) { }

        #endregion [ Constructors ]

        #region [ Tracing Extensions ]

        ///// <summary>
        ///// Gets the tracing connection.
        ///// </summary>
        //private EFTracingConnection TracingConnection
        //{
        //    get { return this.UnwrapConnection<EFTracingConnection>(); }
        //}

        ///// <summary>
        ///// Occurs when [command executing].
        ///// </summary>
        //public event EventHandler<CommandExecutionEventArgs> CommandExecuting
        //{
        //    add { this.TracingConnection.CommandExecuting += value; }
        //    remove { this.TracingConnection.CommandExecuting -= value; }
        //}

        ///// <summary>
        ///// Occurs when [command finished].
        ///// </summary>
        //public event EventHandler<CommandExecutionEventArgs> CommandFinished
        //{
        //    add { this.TracingConnection.CommandFinished += value; }
        //    remove { this.TracingConnection.CommandFinished -= value; }
        //}

        ///// <summary>
        ///// Occurs when [command failed].
        ///// </summary>
        //public event EventHandler<CommandExecutionEventArgs> CommandFailed
        //{
        //    add { this.TracingConnection.CommandFailed += value; }
        //    remove { this.TracingConnection.CommandFailed -= value; }
        //}

        /// <summary>
        /// Appends to log.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EFTracingProvider.CommandExecutionEventArgs"/> instance containing the event data.</param>
        private void AppendToLog(object sender, CommandExecutionEventArgs e)
        {
            //if (this.logOutput != null)
            //{
            //    this.logOutput.WriteLine(e.ToTraceString().TrimEnd());
            //    this.logOutput.WriteLine();
            //}
        }
 internal void RaiseExecuting(CommandExecutionEventArgs e)
 {
     if (this.CommandExecuting != null)
     {
         this.CommandExecuting(this, e);
     }
 }
 internal void RaiseFinished(CommandExecutionEventArgs e)
 {
     if (this.CommandFinished != null)
     {
         this.CommandFinished(this, e);
     }
 }
예제 #10
0
 private void AppendToLog(object sender, CommandExecutionEventArgs e)
 {
     if ( logger != null)
     {
         logger.Debug(e.ToTraceString().TrimEnd());
     }
 }
예제 #11
0
 private void AppendToLog(object sender, CommandExecutionEventArgs e)
 {
     if( null != this.logOutput ) {
         this.logOutput.WriteLine(e.ToTraceString().TrimEnd());
         this.logOutput.WriteLine();
     }
 }
예제 #12
0
 /// <summary>
 /// Executes the command text against the connection.
 /// </summary>
 /// <param name="behavior">An instance of <see cref="T:System.Data.CommandBehavior"/>.</param>
 /// <returns>
 /// A <see cref="T:System.Data.Common.DbDataReader"/>.
 /// </returns>
 protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
 {
     CommandExecutionEventArgs e = new CommandExecutionEventArgs(this, "ExecuteReader");
     e.Status = CommandExecutionStatus.Executing;
     this.Connection.RaiseExecuting(e);
     try
     {
         Stopwatch sw = new Stopwatch();
         sw.Start();
         DbDataReader result = base.ExecuteDbDataReader(behavior);
         sw.Stop();
         e.Result = result;
         e.Status = CommandExecutionStatus.Finished;
         e.Duration = sw.Elapsed;
         this.Connection.RaiseFinished(e);
         return result;
     }
     catch (Exception ex)
     {
         e.Result = ex;
         e.Status = CommandExecutionStatus.Failed;
         this.Connection.RaiseFailed(e);
         throw;
     }
 }
예제 #13
0
        /// <summary>
        /// The logging method.  Overwrite this method to change the logging strategy.
        /// </summary>
        /// <param name="e">
        /// The DB command event.
        /// </param>
        /// <param name="commState">
        /// Command State 
        /// </param>
        private void LogSql(CommandExecutionEventArgs e, CommandState commState)
        {
            switch (commState)
            {
                case CommandState.CommandExecuting:
                    stopwatch.Start();
                    log.InfoFormat(
                        "[Database: {0}] - Executing command {1}", e.Command.Connection.Database, e.ToTraceString());
                    break;
                case CommandState.CommandFailed:
                    stopwatch.Stop();
                    log.InfoFormat(
                        "[Database: {0}] - Executing command {1} was FAILED", e.Command.Connection.Database,
                        e.ToTraceString());
                    break;
                case CommandState.CommandFinished:
                    stopwatch.Stop();
                    if (stopwatch.ElapsedMilliseconds > MaxTimeAllowPerServiceMethod)
                    {
                        log.WarnFormat("Execute for command take: [{0} ms], it is exceed 2s",
                                       stopwatch.ElapsedMilliseconds);
                    }

                    log.InfoFormat("Finished execute command. It takes: {0} millisecond", stopwatch.ElapsedMilliseconds);
                    break;
            }
        }
 private void OnCommandFinished(object sender, CommandExecutionEventArgs e)
 {
     if (_log != null)
     {
         _log.WriteLine(string.Format("#{0} Command completed in {1}", e.CommandId, e.Duration), "Information");
     }
 }
 private void OnCommandFailed(object sender, CommandExecutionEventArgs e)
 {
     if (_log != null)
     {
         _log.WriteLine(string.Format("#{0} Command failed {1}", e.CommandId, e.Result), "Error");
     }
 }
 private void OnCommandExecuting(object sender, CommandExecutionEventArgs e)
 {
     if (_log != null)
     {
         _log.WriteLine(string.Format("#{0} Running {1}:\r\n{2}", e.CommandId, e.Method.Trim(), e.ToTraceString().Trim()), "Information");
     }
 }