How to use App insights connection string with Application Insights Logger Options class for logging?

Anoop Suryadevara 0 Reputation points
2024-08-16T15:10:07.7933333+00:00

User's image

Packages used for web job.

I have been working on moving my webjob application insights settings from using an instrumentation key to using a connection string.  No matter what I try the instrumentation key logs to my app insights but when I set the configuration for app insights to use a connection string it does not fail but it does not log to my app insights.

 

The main reason I am trying to move from the instrumentation key to the connection string is because Microsoft will no longer be supporting instrumentation key in the future.

var appInsights = Environment.GetEnvironmentVariable("APPLICATIONINSIGHTS_CONNECTION_STRING");
if (!string.IsNullOrEmpty(appInsights))
{
var options = new ApplicationInsightsLoggerOptions { ConnectionString = appInsights };

b.AddApplicationInsightsWebJobs(o => o = options);
}
Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sina Salam 26,661 Reputation points Volunteer Moderator
    2024-08-17T16:58:17.8933333+00:00

    Hello Anoop Suryadevara

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that you are facing challenges on the configuration or initialization of the ApplicationInsightsLoggerOptions.

    To configure Application Insights for a WebJob using a connection string instead of an instrumentation key, you need to ensure that you set up the Application Insights SDK correctly and use the connection string in the configuration.

    Three major areas to look into are:

    Accept Answer

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.

    ** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful ** so that others in the community facing similar issues can easily find the solution.

    Best Regards,

    Sina Salam

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.