File tree Expand file tree Collapse file tree 5 files changed +62
-12
lines changed
Expand file tree Collapse file tree 5 files changed +62
-12
lines changed Original file line number Diff line number Diff line change 2828 <PackageReference Include =" OpenTelemetry.Extensions.Hosting" Version =" 1.15.0" />
2929 <PackageReference Include =" OpenTelemetry.Instrumentation.AspNetCore" Version =" 1.15.0" />
3030 <PackageReference Include =" OpenTelemetry.Instrumentation.Http" Version =" 1.15.0" />
31+ <PackageReference Include =" Serilog.AspNetCore" Version =" 8.0.3" />
32+ <PackageReference Include =" Serilog.Sinks.File" Version =" 6.0.0" />
3133 <PackageReference Include =" Swashbuckle.AspNetCore" Version =" 10.1.2" />
3234 <PackageReference Include =" System.IdentityModel.Tokens.Jwt" Version =" 8.15.0" />
3335 </ItemGroup >
Original file line number Diff line number Diff line change 1515using OpenTelemetry . Metrics ;
1616using OpenTelemetry . Resources ;
1717using OpenTelemetry . Trace ;
18+ using Serilog ;
1819
1920var builder = WebApplication . CreateBuilder ( args ) ;
2021
2122builder . Configuration . AddEnvironmentVariables ( "ORUK_API_" ) ;
2223
24+ // Configure Serilog
25+ builder . Host . UseSerilog ( ( context , configuration ) =>
26+ configuration . ReadFrom . Configuration ( context . Configuration ) ) ;
27+
2328// Configure strongly-typed options
2429builder . Services . Configure < SpecificationOptions > (
2530 builder . Configuration . GetSection ( SpecificationOptions . SectionName ) ) ;
@@ -311,6 +316,7 @@ await context.Response.WriteAsync(JsonSerializer.Serialize(new
311316} ) ;
312317
313318app . UseRouting ( ) ;
319+ app . UseSerilogRequestLogging ( ) ;
314320app . UseCors ( ) ;
315321app . UseHttpsRedirection ( ) ;
316322app . UseResponseCaching ( ) ;
@@ -320,3 +326,6 @@ await context.Response.WriteAsync(JsonSerializer.Serialize(new
320326app . MapControllerRoute ( name : "default" , pattern : "{controller}/{action=Index}/{id?}" ) ;
321327
322328app . Run ( ) ;
329+
330+ // Ensure logs are flushed on shutdown
331+ Log . CloseAndFlush ( ) ;
Original file line number Diff line number Diff line change 11{
2- "Logging" : {
3- "LogLevel" : {
2+ "Serilog" : {
3+ "Using" : [" Serilog.Sinks.Console" ],
4+ "MinimumLevel" : {
45 "Default" : " Information" ,
5- "Microsoft.AspNetCore" : " Warning"
6- }
6+ "Override" : {
7+ "Microsoft.AspNetCore" : " Warning" ,
8+ "System.Net.Http.HttpClient" : " Warning"
9+ }
10+ },
11+ "WriteTo" : [
12+ {
13+ "Name" : " Console" ,
14+ "Args" : {
15+ "outputTemplate" : " [{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj} {Properties:j}{NewLine}{Exception}"
16+ }
17+ }
18+ ],
19+ "Enrich" : [" FromLogContext" ]
720 },
821 "AllowedHosts" : " *" ,
922 "Specification" : {
Original file line number Diff line number Diff line change 11{
2- "Logging" : {
3- "LogLevel" : {
2+ "Serilog" : {
3+ "Using" : [" Serilog.Sinks.Console" ],
4+ "MinimumLevel" : {
45 "Default" : " Debug" ,
5- "Microsoft.AspNetCore" : " Information"
6- }
6+ "Override" : {
7+ "Microsoft.AspNetCore" : " Information" ,
8+ "System.Net.Http.HttpClient" : " Information"
9+ }
10+ },
11+ "WriteTo" : [
12+ {
13+ "Name" : " Console" ,
14+ "Args" : {
15+ "outputTemplate" : " [{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj} {Properties:j}{NewLine}{Exception}"
16+ }
17+ }
18+ ],
19+ "Enrich" : [" FromLogContext" ]
720 },
821 "AllowedHosts" : " *" ,
922 "Specification" : {
Original file line number Diff line number Diff line change 11{
2- "Logging" : {
3- "LogLevel" : {
2+ "Serilog" : {
3+ "Using" : [" Serilog.Sinks.Console" ],
4+ "MinimumLevel" : {
45 "Default" : " Information" ,
5- "Microsoft.AspNetCore" : " Warning"
6- }
6+ "Override" : {
7+ "Microsoft.AspNetCore" : " Warning" ,
8+ "System.Net.Http.HttpClient" : " Warning"
9+ }
10+ },
11+ "WriteTo" : [
12+ {
13+ "Name" : " Console" ,
14+ "Args" : {
15+ "outputTemplate" : " [{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj} {Properties:j}{NewLine}{Exception}"
16+ }
17+ }
18+ ],
19+ "Enrich" : [" FromLogContext" ]
720 },
821 "AllowedHosts" : " *" ,
922 "Specification" : {
You can’t perform that action at this time.
0 commit comments