using Microsoft.Extensions.Logging; using Microsoft.ApplicationInsights; using Microsoft.ApplicationInsights.Extensibility; ILoggerFactory loggerFactory = LoggerFactory.Create(builder => { builder.AddApplicationInsights( options => options .SetInstrumentationKey("your_instrumentation_key") .AddProcessor(new AdaptiveSamplingTelemetryProcessor(new FixedSamplingPercentage(50))) ); }) ILogger logger = loggerFactory.CreateLogger("ExampleLogger"); logger.LogInformation("Hello, World!");
using Microsoft.Extensions.Logging; using Microsoft.ApplicationInsights; ILoggerFactory loggerFactory = LoggerFactory.Create(builder => { builder.AddApplicationInsights("your_instrumentation_key"); }) ILogger logger = loggerFactory.CreateLogger("ExampleLogger"); logger.LogInformation("Hello, World!");In this example, we are adding Application Insights telemetry to the logger using the AddApplicationInsights method with just the instrumentation key as a parameter. Package library: Microsoft.Extensions.Logging.ApplicationInsights