Here you will find App Metrics configuration options related to integrating App Metrics in an ASP.NET Core application.
When bootstrapping an ASP.NET Core application in Program.cs
using the Microsoft.Extensions.Hosting.Host
, App Metrics core functionality can be configured using extension methods provided on Microsoft.Extensions.Hosting.IHostBuilder.
Modifying or extending a MetricsBuilder
that is pre-configured with the defaults configuration:
...
public static IHost BuidHost(string[] args)
{
return Host.CreateDefaultBuilder(args)
.ConfigureMetricsWithDefaults(
builder =>
{
builder.Configuration.Configure(
options =>
{
options.DefaultContextLabel = "Testing";
options.Enabled = false;
});
})
.UseMetrics()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
.Build();
}
...
Using a MetricsBuilder
where you define the desired configuration without defaults:
...
public static IHost BuidHost(string[] args)
{
return Host.CreateDefaultBuilder(args)
.ConfigureMetrics(
builder =>
{
builder.Configuration.Configure(
options =>
{
options.DefaultContextLabel = "Testing";
options.Enabled = false;
});
})
.UseMetrics()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
.Build();
}
...
Optionally, App Metrics core functionality can be configured in an ASP.NET Core application using the Startup.cs
rather than bootstrapping on the Host
. This is done by using the MetricsBuilder
directly and the Microsoft.Extensions.DependencyInjection.IServiceCollection extension methods provided by App Metrics.
Modifying or extending a MetricsBuilder
that is pre-configured with the defaults configuration:
public class Startup
{
public void Configure(IApplicationBuilder app)
{
app.UseMvc();
}
public void ConfigureServices(IServiceCollection services)
{
var metrics = AppMetrics.CreateDefaultBuilder()
... // configure other options
.Build();
services.AddMetrics(metrics);
services.AddMvc().AddMetrics();
}
}
Using a MetricsBuilder
where you define the desired configuration without defaults:
public class Startup
{
public void Configure(IApplicationBuilder app)
{
app.UseMvc();
}
public void ConfigureServices(IServiceCollection services)
{
var metrics = new MetricsBuilder()
... // configure other options
.Build();
services.AddMetrics(metrics);
services.AddMvc().AddMetrics();
}
}
For more details App Metrics core configuration options, refer to the configuration fundamentals documentation.
For details on configuring App.Metrics.AspNetCore.Tracking, see the ASP.NET Core Web Metrics documentation.
For details on configuring App.Metrics.AspNetCore.Endpoints, see the ASP.NET Core Endpoints documentation.