Created
August 19, 2021 17:38
-
-
Save kasobol-msft/7fb766984c789c2b204b85a96c90b5cb to your computer and use it in GitHub Desktop.
.NET logging from bare bone app.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace ConsoleApp2 | |
{ | |
using Azure.Identity; | |
using Azure.Storage.Blobs; | |
using Azure.Storage.Blobs.Models; | |
using Microsoft.ApplicationInsights.DependencyCollector; | |
using Microsoft.ApplicationInsights.EventSourceListener; | |
using Microsoft.ApplicationInsights.Extensibility; | |
using System; | |
using System.Threading.Tasks; | |
class Program | |
{ | |
static async Task Main(string[] args) | |
{ | |
using TelemetryConfiguration configuration = TelemetryConfiguration.CreateDefault(); | |
configuration.InstrumentationKey = "REDACTED"; | |
using var module = new DependencyTrackingTelemetryModule(); | |
// initialize the module | |
module.Initialize(configuration); | |
using var module2 = new EventSourceTelemetryModule(); | |
module2.Sources.Add(new EventSourceListeningRequest() | |
{ | |
Name = "Azure", | |
PrefixMatch = true, | |
Level = System.Diagnostics.Tracing.EventLevel.LogAlways | |
}); | |
module2.Initialize(configuration); | |
Console.WriteLine("Hello World!"); | |
var defaultCredential = new DefaultAzureCredential(); | |
var client = new BlobServiceClient(new Uri("REDACTED"), defaultCredential); | |
BlobServiceProperties props = await client.GetPropertiesAsync(); | |
Console.WriteLine(props.DefaultServiceVersion); | |
Console.WriteLine("End"); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net5.0</TargetFramework> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Azure.Identity" Version="1.4.0" /> | |
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.18.0" /> | |
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.18.0" /> | |
<PackageReference Include="Microsoft.ApplicationInsights.EventSourceListener" Version="2.18.0" /> | |
</ItemGroup> | |
<ItemGroup> | |
<ProjectReference Include="..\Azure.Storage.Blobs\src\Azure.Storage.Blobs.csproj" /> | |
</ItemGroup> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment