Search code examples
c#.net-coremetrics

How to disable all trace logs from App.Mertics


I'm trying to add metrics to my web application (.net core 3.1). everything work fine, but I faced with the fact that metrics spam into my logger some trace information:

mongoDB logs

App-Metrics spam into logs so often that I get ~100 megabytes of useless logs every 2-3 hours. Unfortunate, I didnt find anything about internal logs at https://www.app-metrics.io/web-monitoring/aspnet-core/reporting/ The only thing than I got: I disabled reporting. It reduced count of logs, but there are still a lot of them (and all of them, as for me, dont contains any useful information).

program.cs:

    public static void Main(string[] args)
    {
        Metrics = AppMetrics.CreateDefaultBuilder().Configuration
            .Configure(options => options.ReportingEnabled = false)
            .OutputMetrics.AsPrometheusPlainText()
            .Build();

        CreateHostBuilder(args).Build().Run();
    }

    public static IHostBuilder CreateHostBuilder(string[] args)
    {
        var builder = Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());

        builder = builder.ConfigureMetrics(Metrics)
            .ConfigureAppMetricsHostingConfiguration(options => options.MetricsTextEndpoint = "/metrics")
            .UseMetrics(options =>
            {
                options.EndpointOptions = endpointsOptions =>
                {
                    endpointsOptions.MetricsTextEndpointOutputFormatter = Metrics.OutputMetricsFormatters
                        .OfType<MetricsPrometheusTextOutputFormatter>().First();
                };
            })
            .UseMetricsEndpoints(options => options.MetricsEndpointEnabled = false);

        return builder;
    }

Can I somehow disable all logs from App-Metrics(or at least disable all trace information)?


Solution

  • there is no way to disable internal/trace logs from App.Mertics. I was able to disable trace logs only at Nlog config:

    <?xml version="1.0" encoding="utf-8" ?>
    <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      /// ....
      <rules>
        <logger name="App.Metrics.*" minLevel="Info" />
      </rules>
    </nlog>