コード例 #1
0
        void FillDbCommandParams(ChloeDbCommandEventData eventData, IDbCommand command)
        {
            foreach (IDbDataParameter item in command.Parameters)
            {
                DbCommandParam p = new DbCommandParam();
                p.Name   = item.ParameterName;
                p.Value  = item.Value == DBNull.Value ? null : item.Value;
                p.DbType = item.DbType;

                eventData.Parameters.Add(p);
            }
        }
コード例 #2
0
        public void ScalarExecuting(IDbCommand command, DbCommandInterceptionContext <object> interceptionContext)
        {
            interceptionContext.DataBag.Add("startTime", DateTime.Now);
            if (_diagnosticListener.IsEnabled(ChloeDiagnosticListenerNames.ScalarExecuting))
            {
                var eventData = new ChloeDbCommandEventData()
                {
                    CommandText = command.CommandText,
                    ElapsedTime = null,
                    Exception   = null
                };

                this.FillDbCommandParams(eventData, command);

                _diagnosticListener.Write(ChloeDiagnosticListenerNames.ScalarExecuting, eventData);
            }
        }
コード例 #3
0
        public void NonQueryExecuted(IDbCommand command, DbCommandInterceptionContext <int> interceptionContext)
        {
            if (_diagnosticListener.IsEnabled(ChloeDiagnosticListenerNames.NonQueryExecuted))
            {
                DateTime startTime = (DateTime)(interceptionContext.DataBag["startTime"]);
                var      eventData = new ChloeDbCommandEventData()
                {
                    CommandText = command.CommandText,
                    ElapsedTime = (long)DateTime.Now.Subtract(startTime).TotalMilliseconds,
                    Exception   = interceptionContext.Exception
                };

                this.FillDbCommandParams(eventData, command);

                _diagnosticListener.Write(ChloeDiagnosticListenerNames.NonQueryExecuted, eventData);
            }
        }