Exemple #1
0
        private TResult ExecuteWrap <TResult>(Func <TResult> executeImpl, ExecutionContext executionContext
                                              , [CallerMemberName] string operation = "")
        {
            Stopwatch stopwatch   = null;
            var       operationId = Guid.Empty;

            try
            {
                if (_logger.IsEnabled(LogLevel.Debug))
                {
                    stopwatch = Stopwatch.StartNew();
                }
                operationId = _diagnosticListener.WriteCommandExecuterExecuteBefore(executionContext, operation);
                var result = executeImpl();
                _diagnosticListener.WriteCommandExecuterExecuteAfter(operationId, executionContext, operation);
                return(result);
            }
            catch (Exception ex)
            {
                _diagnosticListener.WriteCommandExecuterExecuteError(operationId, executionContext, ex, operation);
                throw;
            }
            finally
            {
                if (_logger.IsEnabled(LogLevel.Debug))
                {
                    _logger.LogDebug(
                        $"Operation:{operation} Statement.Id:{executionContext.Request.FullSqlId} Execute Taken:{stopwatch?.ElapsedMilliseconds}.");
                }
            }
        }