Configuration on ASP.NET Coreedit

The UseElasticApm() extension method offers an overload to pass an IConfiguration instance to the APM Agent. By using this overload in a typical ASP.NET Core application, the Startup.cs file would contain code similar to the following:

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        //Registers the agent with an IConfiguration instance:
        app.UseElasticApm(Configuration);

        //Rest of the Configure() method...
    }
}

With this you can use any configuration source that you configured on the IConfiguration instance that you passed to the APM Agent. You can find the key of each configuration below in the IConfiguration key column.

Note

By simply calling app.UseElasticApm() without the overload, the agent will read configurations only from environment variables.

Sample configuration fileedit

Below is a sample appsettings.json configuration file for a typical ASP.NET Core application. There are two important takeaways:

  1. The part below ElasticApm is fetched by the agent if the corresponding IConfiguration is passed to the agent.
  2. With ASP.NET Core, you must set LogLevel for the internal APM logger in the standard `Logging section with the ElasticApm category name.
{
  "Logging": {
    "LogLevel": {
      "Default": "Warning",
      "Elastic.Apm": "Debug"
    }
  },
  "AllowedHosts": "*",
  "ElasticApm":
    {
      "ServerUrls":  "http://myapmserver:8200",
      "TransactionSampleRate": 1.0
    }
}

In certain scenarios — like when you’re not using ASP.NET Core — you wont activate the agent with the UseElasticApm() method. In this case, you can set the log level of the agent with ElasticApm:LogLevel, as shown in the following appsettings.json file:

{
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ElasticApm":
    {
      "LogLevel":  "Debug",
      "ServerUrls":  "http://myapmserver:8200",
      "TransactionSampleRate": 1.0
    }
}