简体   繁体   中英

How to configure ApplicationInsightsTelemetry, in .NET Core Web Api

I am trying to adapt Application Insights to my liking. And I have some problems. I have it mounted like this. In the startup.cs class:

public void ConfigureServices(IServiceCollection services)
{
    services.AddApplicationInsightsTelemetry();
            
    services.AddControllers();
}

In the Program.cs:

public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureLogging(logging =>
                {
                    logging.AddApplicationInsights("73985d32-dc3b-4a7e-915e-aa7ef37fbef8");
                    logging.AddFilter<ApplicationInsightsLoggerProvider>("", LogLevel.Information);
                })
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });

So I avoid using the appsettings.json configuration, because the log level will be variable. My first question is, how can I make the dynamic log level, by querying the database? Another question, is how can I add a custom parameter, type customer_name?

Finally, how can I make Application Insights register the values that I want, using: Only record the values that come out of these functions, for example, if there is an exception, you would not have to register it.

_logger.LogInformation("Test info");
_logger.LogError(ex, ex.Message);

About your first question

I think it's impossible,for more details, you can check bowman's answer.

Overriding Log Level for Azure Functions

About second question

Jitendra Patil's code really great, this should be what you need.

Adding custom properties for each request in Application Insights metrics

在此处输入图像描述

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM