/// <inheritdoc />
        public Task WriteAsync(
            Stream output,
            MetricsDataValueSource metricsData,
            CancellationToken cancellationToken = default)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            var serializer = new MetricSnapshotSerializer();

            using (var streamWriter = new StreamWriter(output))
            {
                using (var textWriter = new MetricSnapshotHostedMetricsJsonWriter(
                           streamWriter,
                           _flushInterval,
                           _options.MetricNameFormatter))
                {
                    serializer.Serialize(textWriter, metricsData, MetricFields);
                }
            }

#if !NETSTANDARD1_6
            return(AppMetricsTaskHelper.CompletedTask());
#else
            return(Task.CompletedTask);
#endif
        }
コード例 #2
0
        /// <inheritdoc />
        public async Task WriteAsync(
            Stream output,
            MetricsDataValueSource metricsData,
            CancellationToken cancellationToken = default)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            var serializer = new MetricSnapshotSerializer();

            await using var jsonWriter = new MetricSnapshotHostedMetricsJsonWriter(
                            output,
                            _flushInterval,
                            _options.MetricNameFormatter);

            serializer.Serialize(jsonWriter, metricsData, MetricFields);
        }