Using serilog with azure application insights and .Net core Using serilog with azure application insights and .Net core azure azure

Using serilog with azure application insights and .Net core


Please follow the steps below:

First, in stall the following packages:

Microsoft.ApplicationInsights.AspNetCore, version 2.14.0

Serilog.AspNetCore, version 3.2.0

Serilog.Sinks.ApplicationInsights, version 3.1.0

Serilog.Settings.Configuration, version 3.1.0

In Program.cs:

public class Program{         public static void Main(string[] args)    {        CreateHostBuilder(args).Build().Run();    }    public static IHostBuilder CreateHostBuilder(string[] args) =>        Host.CreateDefaultBuilder(args)            .ConfigureWebHostDefaults(webBuilder =>            {                webBuilder.UseStartup<Startup>();            })           .UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration                    .ReadFrom.Configuration(hostingContext.Configuration)                    .WriteTo.ApplicationInsights(new TelemetryConfiguration{ InstrumentationKey = "xxxxxxxxx" },TelemetryConverter.Traces)             );                }

In controller.cs:

enter image description here

The test result:

enter image description here