Soru

Zorluk: KolayConfigure Application Insights Instrumentation and Telemetry

You are developing a worker utility in C# that processes queue messages. You need to configure Application Insights telemetry programmatically without using dependency injection. Complete the following C# code snippet to initialize the telemetry configuration and apply the connection string. What are the correct API members to write in the blanks?

Cevap:TelemetryConfiguration config = TelemetryConfiguration.【CreateDefault】();
config.【ConnectionString】 = "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://eastus-0.in.applicationinsights.azure.com/";
TelemetryClient client = new TelemetryClient(config);

Cevap

Use 'CreateDefault' to instantiate the default configuration and 'ConnectionString' to set the Azure Monitor connection string.
To manually configure telemetry in C#, TelemetryConfiguration.CreateDefault() is invoked to create a configuration instance with default settings. The ConnectionString property is then assigned the connection string of the Application Insights resource. A TelemetryClient is subsequently initialized using this configuration.

Adım Adım Çözüm

1
Identify the factory method on TelemetryConfiguration to instantiate the configuration.
TelemetryConfiguration.CreateDefault()
It returns a new TelemetryConfiguration instance pre-configured with standard telemetry initializers and channels.
2
Identify the property of TelemetryConfiguration that holds the ingestion parameters.
ConnectionString
The ConnectionString property replaced the deprecated InstrumentationKey property to route and authenticate telemetry data securely.

Anahtar Kavram

Manual initialization of Application Insights telemetry configuration in .NET applications
Bu soruyu puanla