Beispiel #1
0
        public static async Task ReadDataAsync()
        {
            await foreach (var value in GlobalChannel.Reader.ReadAllAsync())
            {
                using var md = _metricsProvider.TrackAndDuration("ConsoleWithMetrics_ConsoleWrite");

                await Console.Out.WriteLineAsync(
                    $"{DateTime.Now:MM/dd/yyyy hh:mm:ss.fff} - {value}").ConfigureAwait(false);
            }
        }
Beispiel #2
0
        public TransformBlock <TState, TState> GetWrappedTransformBlock(
            Func <TState, TState> action,
            ExecutionDataflowBlockOptions options,
            string metricIdentifier,
            bool metricMicroScale    = false,
            string metricDescription = null)
        {
            TState WrapAction(TState state)
            {
                try
                {
                    using var multiDispose = _metricsProvider.TrackAndDuration(metricIdentifier, metricMicroScale, metricDescription);
                    return(action(state));
                }
                catch (Exception ex)
                {
                    state.IsFaulted = true;
                    state.EDI       = ExceptionDispatchInfo.Capture(ex);
                    return(state);
                }
            }

            return(new TransformBlock <TState, TState>(WrapAction, options));
        }