Text File

The App.Metrics.Reporting.TextFile nuget package writes metrics to a text file. The default output is plain text using App.Metrics.Formatters.Ascii which can be substituted with any other App Metrics Formatter.

Getting started

To use the text file reporter, first install the nuget package:

nuget install App.Metrics.Reporting.TextFile

Then enable the reporter using Report.ToTextFile():

var metrics = new MetricsBuilder()

If not output file name is specified, the default path is the application execution path and file name metrics.txt. The output path and file name can be specified as ToTextFile(@"C:\metrics.txt")

See Reporting for details on configuring metric report scheduling.


Configuration options are provided as a setup action used with ToTextFile().

To configure text file reporting options:

var filter = new MetricsFilter().WhereType(MetricType.Timer);
var metrics = new MetricsBuilder()
        options => {
            options.MetricsOutputFormatter = new MetricsJsonOutputFormatter();
            options.AppendMetricsToTextFile = true;
            options.Filter = filter;
            options.FlushInterval = TimeSpan.FromSeconds(20);
            options.OutputPathAndFileName = @"C:\metrics.txt";

The configuration options provided are:

Option Description
MetricsOutputFormatter The formatter used when writing metrics to disk.
AppendMetricsToTextFile If true appends metrics to the output file, if false overrides the file context with the current metrics snapshot on each run.
Filter The filter used to filter metrics just for this reporter.
FlushInterval The delay between flushing metrics to disk.
OutputPathAndFileName The absolute path and file name where metrics are written.