I created a sample ASP.NET core 8.0 Application and successfully configured authentication, can view traces and their detailed descriptions without any issues.
Make sure you install the latest versions of the below packages.
Serilog
Serilog.Sinks.Console
Serilog.Sinks.ApplicationInsights
My program.cs:
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.Identity.Web;
using Serilog;
using Serilog.Sinks.ApplicationInsights;
var builder = WebApplication.CreateBuilder(args);
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug().
.WriteTo.Console()
.Enrich.FromLogContext() .WriteTo.ApplicationInsights(builder.Configuration["ApplicationInsights:ConnectionString"], TelemetryConverter.Traces)
.CreateLogger();
builder.Host.UseSerilog();
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();
builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"));
builder.Services.AddApplicationInsightsTelemetry();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler(errorApp =>
{
errorApp.Run(async context =>
{
context.Response.StatusCode = 500;
context.Response.ContentType = "text/html";
var exceptionHandlerPathFeature = context.Features.Get<Microsoft.AspNetCore.Diagnostics.IExceptionHandlerPathFeature>();
var exception = exceptionHandlerPathFeature?.Error;
Log.Error(exception, "An unhandled exception occurred.");
await context.Response.WriteAsync("<h1>Something went wrong.</h1>");
});
});
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapRazorPages();
});
var logger = Log.ForContext("SourceContext", "Startup");
logger.Information("Application started successfully.");
app.Run();
appsettings.json:
{
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "MicrosoftFieldLedSandbox.onmicrosoft.com",
"TenantId": "<Tenant-id>",
"ClientId": "<client-id>",
"CallbackPath": "/signin-oidc",
"ClientSecret": "<client-secret>",
"ClientCertificates": []
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"MicrosoftGraph": {
"BaseUrl": "https://graph.microsoft.com/v1.0",
"Scopes": "user.read"
},
"DownstreamApi": {
"BaseUrl": "https://graph.microsoft.com/v1.0",
"Scopes": [
"access_as_user"
]
},
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"WriteTo": [
{ "Name": "Console" },
{
"Name": "ApplicationInsights",
"Args": { "connectionString": "<connection-string>" }
}
],
"Enrich": [ "FromLogContext" ]
},
"ApplicationInsights": {
"ConnectionString": "<connection-string>"
}
}
csproj file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-example1insights-<your-ID> </UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.10" NoWarn="NU1605" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.10" NoWarn="NU1605" />
<PackageReference Include="Microsoft.Identity.Web" Version="2.19.1" />
<PackageReference Include="Microsoft.Identity.Web.MicrosoftGraph" Version="2.19.1" />
<PackageReference Include="Microsoft.Identity.Web.UI" Version="2.19.1" />
<PackageReference Include="Microsoft.Identity.Web.DownstreamApi" Version="2.19.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.2" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
</ItemGroup>
</Project>
Successfully authenticated my app

In my App insights I can view the traces and their detailed descriptions.


Transaction searchblade instead ofAvailabilityblade to get the error/exception details.. Could you pls help check in that menu?