- ASP.NET Core Web App
- Uses
Serilog.AspNetCore
to get information about ASP.NET's internal operations written to the same Serilog sinks as your application events. - Uses
Serilog.Sinks.ApplicationInsights
to write events to Microsoft Application Insights.
-
Create ASP.NET Core Web App:
dotnet new webapp --name Serilog.Samples.WebApp
-
Add Serilog packages:
dotnet add package Serilog.AspNetCore dotnet add package Serilog.Sinks.ApplicationInsights
-
Configure web host to
UseSerilog
(reference):.UseSerilog((hostingContext, services, loggerConfiguration) => loggerConfiguration .Enrich.FromLogContext() .WriteTo.File(new CompactJsonFormatter(), "logs\\myapp.json", rollingInterval: RollingInterval.Day) .WriteTo.Console() .WriteTo.ApplicationInsights(new TelemetryClient(new TelemetryConfiguration("<ikey>")), new TraceTelemetryConverter()));
-
Create some log output messages (reference).
-
Run the application:
dotnet run