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?
Answer: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);
config.【ConnectionString】 = "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://eastus-0.in.applicationinsights.azure.com/";
TelemetryClient client = new TelemetryClient(config);
Answer
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.
Step-by-Step Solution
Key Concept
Manual initialization of Application Insights telemetry configuration in .NET applications