ASP.NET Core Middleware JSON Formatting
To serialize metrics, environment information and/or health as JSON when /metrics
, /metrics-text
, /env
and/or /health
are requested:
- Add the App.Metrics.Formatters.Json nuget package to your ASP.NET Core web application.
- Configure JSON serialization in your
Startup.cs
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(options => options.AddMetricsResourceFilter());
services.AddMetrics()
// .AddJsonSerialization() - Enables json format on the /metrics-text, /metrics, /health and /env endpoints.
.AddJsonMetricsSerialization() // Enables json format on the /metrics-text endpoint.
.AddJsonMetricsTextSerialization() // Enables json format on the /metrics endpoint.
.AddJsonHealthSerialization() // Enables json format on the /health endpont.
.AddJsonEnvironmentInfoSerialization() // Enables json format on the /env endpont.
.AddHealthChecks()
.AddMetricsMiddleware();
}
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
app.UseMetrics();
app.UseMvc();
}
}