From 4594a760648aeced6bd9858a0c94ace5cd0e0f9e Mon Sep 17 00:00:00 2001 From: Timothy Mothra Date: Thu, 30 Jun 2022 13:42:58 -0700 Subject: [PATCH] update example with sample code for aad (#2617) --- examples/ConsoleApp/ConsoleApp.csproj | 4 ++++ examples/ConsoleApp/Program.cs | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/examples/ConsoleApp/ConsoleApp.csproj b/examples/ConsoleApp/ConsoleApp.csproj index f2b026e36e..53585bad83 100644 --- a/examples/ConsoleApp/ConsoleApp.csproj +++ b/examples/ConsoleApp/ConsoleApp.csproj @@ -5,6 +5,10 @@ net6.0 + + + + diff --git a/examples/ConsoleApp/Program.cs b/examples/ConsoleApp/Program.cs index 9ef70cdec2..6b7b8613f4 100644 --- a/examples/ConsoleApp/Program.cs +++ b/examples/ConsoleApp/Program.cs @@ -1,4 +1,6 @@ -using Microsoft.ApplicationInsights; +using Azure.Identity; + +using Microsoft.ApplicationInsights; using Microsoft.ApplicationInsights.Channel; using Microsoft.ApplicationInsights.DataContracts; using Microsoft.ApplicationInsights.Extensibility; @@ -26,6 +28,14 @@ static void Main(string[] args) // Add custom TelemetryInitializer services.AddSingleton(); + // Configure TelemetryConfiguration + services.Configure(config => + { + // Optionally configure AAD + //var credential = new DefaultAzureCredential(); + //config.SetAzureTokenCredential(credential); + }); + // Being a regular console app, there is no appsettings.json or configuration providers enabled by default. // Hence connection string must be specified here. services.AddApplicationInsightsTelemetryWorkerService((ApplicationInsightsServiceOptions options) => options.ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000");