Skip to content

Commit

Permalink
update example with sample code for aad (#2617)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyMothra authored Jun 30, 2022
1 parent a2b56d5 commit 4594a76
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions examples/ConsoleApp/ConsoleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.6.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\NETCORE\src\Microsoft.ApplicationInsights.WorkerService\Microsoft.ApplicationInsights.WorkerService.csproj" />
</ItemGroup>
Expand Down
12 changes: 11 additions & 1 deletion examples/ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -26,6 +28,14 @@ static void Main(string[] args)
// Add custom TelemetryInitializer
services.AddSingleton<ITelemetryInitializer, MyCustomTelemetryInitializer>();

// Configure TelemetryConfiguration
services.Configure<TelemetryConfiguration>(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");
Expand Down

0 comments on commit 4594a76

Please sign in to comment.