-1

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);
Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
vidgarga
  • 320
  • 1
  • 3
  • 8
  • If you want to make dynamic logging to AI, you have to implement an `ITelemetryProcessor`. Then your logger has to *always* push the messages to AI and your processor makes the filtering (by omitting the call to `_next.Process(item);`). – Oliver May 14 '21 at 09:38
  • Does my answer useful to you ? – Jason Pan May 18 '21 at 05:52

1 Answers1

0

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

enter image description here

enter image description here

Jason Pan
  • 15,263
  • 1
  • 14
  • 29