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")

App Metrics at the moment leaves report scheduling up the the user unless using App.Metrics.AspNetCore.Reporting . To run all configured reports use the ReportRunner on IMetricsRoot:

await metrics.ReportRunner.RunAllAsync();

Report Scheduling will be added when Microsoft.Extensions.Hosting.Background is released, otherwise there are various other scheduling solutions available for C#. For ASP.NET Core reporting see details on the App.Metrics.AspNetCore.Reporting support package.


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.