Skip to content
Michael Schnyder edited this page Aug 11, 2015 · 4 revisions

Configuration of the metrics library can be done using the Config property of the static Metric class.

Global context name

The root context name for metrics inside a process can be configured in the following ways (in decreasing order of priority):

  1. Set the environment variable: Metrics.GlobalContextName
  2. Set the app settings key Metrics.GlobalContextName
  3. If none of the above is set the default is MachineName.ProcessName

The global context name can contain the following variable placeholders:

  • $Env.MachineName$ will be replaced with the machine name
  • $End.ProcessName$ will be replaced with the process name
  • $Env.AppDomainAppVirtualPath$ will be replaced with the app virtual path
  • $Env.$ will be replaced with the corresponding environment variable
Sample config
Metric.Config
    .WithHttpEndpoint("http://localhost:1234/metrics/")
    .WithAllCounters()
    .WithInternalMetrics()
    .WithReporting(config => config
        .WithConsoleReport(TimeSpan.FromSeconds(30))
        .WithCSVReports(@"c:\temp\reports\", TimeSpan.FromMinutes(30))
        .WithTextFileReport(@"C:\temp\reports\metrics.txt", TimeSpan.FromHours(1))
    );
App.Config settings

The following settings can be placed in the app.config ( or web.config ) file to control a few aspects of the Metrics.NET library:

<!-- Completely disable all metrics -->
<add key="Metrics.CompletelyDisableMetrics" value="true"/>

<!-- Equivalent of calling Metric.Config.WithHttpEndpoint("http://localhost:1234/") -->
<add key="Metrics.HttpListener.HttpUriPrefix" value="http://localhost:1234/"/>

<!-- Equivalent of calling 
Metric.Config.WithReporting(config => 
config.WithCSVReports(@"..\MetricsCSV\", TimeSpan.FromSeconds(10))
-->
<add key="Metrics.CSV.Path" value="..\MetricsCSV\"/>
<add key="Metrics.CSV.Interval.Seconds" value="10"/>