You are developing a C# .NET 8 console application that runs on-premises and needs to manually send custom exception reports to Azure Application Insights. You retrieve the connection string from a secure local store.
You write the following code:
csharp
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
var connectionString = GetSecureConnectionString();
var configuration = TelemetryConfiguration.CreateDefault();
// INSERT CODE HERE
var telemetryClient = new TelemetryClient(configuration);
You need to complete the code to ensure that the Application Insights SDK is properly initialized and telemetry data is transmitted to the correct Azure resource. Which line of code should you insert?
- configuration.ConnectionString = connectionString;Cevap
- Bconfiguration.InstrumentationKey = connectionString;
- CtelemetryClient.Context.ConnectionString = connectionString;
- DtelemetryClient.InstrumentationKey = connectionString;
Cevap
Assign the retrieved connection string to the ConnectionString property of the TelemetryConfiguration object.
Assigning the connection string to configuration.ConnectionString correctly configures the telemetry endpoint and credentials for the TelemetryConfiguration object, which is then passed to the TelemetryClient constructor. This ensures that the SDK knows where to send telemetry data.
Adım Adım Çözüm
Anahtar Kavram
Configuring Application Insights manually using TelemetryConfiguration and ConnectionString