diff --git a/src/ApiGateway/src/ApiGateway.csproj b/src/ApiGateway/src/ApiGateway.csproj
index 35f3ce0..5eda3b5 100644
--- a/src/ApiGateway/src/ApiGateway.csproj
+++ b/src/ApiGateway/src/ApiGateway.csproj
@@ -5,12 +5,6 @@
enable
-
-
-
-
-
-
diff --git a/src/BuildingBlocks/BuildingBlocks.csproj b/src/BuildingBlocks/BuildingBlocks.csproj
index e3c5308..c8dd0c0 100644
--- a/src/BuildingBlocks/BuildingBlocks.csproj
+++ b/src/BuildingBlocks/BuildingBlocks.csproj
@@ -61,6 +61,7 @@
+
@@ -91,7 +92,9 @@
-
+
+
+
diff --git a/src/BuildingBlocks/Logging/Extensions.cs b/src/BuildingBlocks/Logging/Extensions.cs
index d031f23..6fc02ff 100644
--- a/src/BuildingBlocks/Logging/Extensions.cs
+++ b/src/BuildingBlocks/Logging/Extensions.cs
@@ -1,9 +1,11 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Enrichers.Span;
using Serilog.Events;
+using Serilog.Exceptions;
using Serilog.Sinks.SpectreConsole;
namespace BuildingBlocks.Logging;
@@ -12,20 +14,27 @@ public static class Extensions
{
public static WebApplicationBuilder AddCustomSerilog(this WebApplicationBuilder builder)
{
+ Log.Logger = new LoggerConfiguration()
+ .WriteTo.Console()
+ .CreateBootstrapLogger();
- Log.Logger = new LoggerConfiguration()
- .WriteTo.Console()
- .CreateBootstrapLogger();
+ builder.Host.UseSerilog((context, loggerConfiguration) =>
+ {
+ var loggOptions = context.Configuration.GetSection(nameof(LogOptions)).Get();
- builder.Host.UseSerilog((ctx, lc) => lc
- .WriteTo.Console()
- .WriteTo.SpectreConsole("{Timestamp:HH:mm:ss} [{Level:u4}] {Message:lj}{NewLine}{Exception}",
- LogEventLevel.Error)
+ var logLevel = Enum.TryParse(loggOptions.Level, true, out var level)
+ ? level
+ : LogEventLevel.Information;
+
+ loggerConfiguration.WriteTo.Console()
+ .WriteTo.SpectreConsole(loggOptions.LogTemplate, logLevel)
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Error)
.Enrich.WithSpan()
+ .Enrich.WithExceptionDetails()
.Enrich.FromLogContext()
- .ReadFrom.Configuration(ctx.Configuration));
+ .ReadFrom.Configuration(context.Configuration);
+ });
- return builder;
+ return builder;
}
}
diff --git a/src/BuildingBlocks/Logging/LoggerOptions.cs b/src/BuildingBlocks/Logging/LoggerOptions.cs
new file mode 100644
index 0000000..7bc99fa
--- /dev/null
+++ b/src/BuildingBlocks/Logging/LoggerOptions.cs
@@ -0,0 +1,7 @@
+namespace BuildingBlocks.Logging;
+
+public class LogOptions
+{
+ public string Level { get; set; }
+ public string LogTemplate { get; set; }
+}
diff --git a/src/Services/Booking/src/Booking.Api/appsettings.json b/src/Services/Booking/src/Booking.Api/appsettings.json
index 423f603..47f9d07 100644
--- a/src/Services/Booking/src/Booking.Api/appsettings.json
+++ b/src/Services/Booking/src/Booking.Api/appsettings.json
@@ -2,14 +2,9 @@
"AppOptions": {
"Name": "Booking-Service"
},
- "Serilog": {
- "MinimumLevel": {
- "Default": "Information",
- "Override": {
- "Microsoft": "Warning",
- "Microsoft.Hosting.Lifetime": "Information"
- }
- }
+ "LogOptions": {
+ "Level": "Information",
+ "LogTemplate": "{Timestamp:HH:mm:ss} [{Level:u4}] {Message:lj}{NewLine}{Exception}"
},
"ConnectionStrings": {
"DefaultConnection": "Server=.\\sqlexpress;Database=BookingDB;Trusted_Connection=True;MultipleActiveResultSets=true"
diff --git a/src/Services/Flight/src/Flight.Api/appsettings.json b/src/Services/Flight/src/Flight.Api/appsettings.json
index a228d34..9dc79d2 100644
--- a/src/Services/Flight/src/Flight.Api/appsettings.json
+++ b/src/Services/Flight/src/Flight.Api/appsettings.json
@@ -2,14 +2,9 @@
"AppOptions": {
"Name": "Flight-Service"
},
- "Serilog": {
- "MinimumLevel": {
- "Default": "Information",
- "Override": {
- "Microsoft": "Warning",
- "Microsoft.Hosting.Lifetime": "Information"
- }
- }
+ "LogOptions": {
+ "Level": "Information",
+ "LogTemplate": "{Timestamp:HH:mm:ss} [{Level:u4}] {Message:lj}{NewLine}{Exception}"
},
"ConnectionStrings": {
"DefaultConnection": "Server=.\\sqlexpress;Database=FlightDB;Trusted_Connection=True;MultipleActiveResultSets=true"
diff --git a/src/Services/Identity/src/Identity.Api/appsettings.json b/src/Services/Identity/src/Identity.Api/appsettings.json
index 6571c39..bc7d45d 100644
--- a/src/Services/Identity/src/Identity.Api/appsettings.json
+++ b/src/Services/Identity/src/Identity.Api/appsettings.json
@@ -11,14 +11,9 @@
"UserName": "guest",
"Password": "guest"
},
- "Serilog": {
- "MinimumLevel": {
- "Default": "Information",
- "Override": {
- "Microsoft": "Warning",
- "Microsoft.Hosting.Lifetime": "Information"
- }
- }
+ "LogOptions": {
+ "Level": "Information",
+ "LogTemplate": "{Timestamp:HH:mm:ss} [{Level:u4}] {Message:lj}{NewLine}{Exception}"
},
"AllowedHosts": "*"
}
diff --git a/src/Services/Passenger/src/Passenger.Api/appsettings.json b/src/Services/Passenger/src/Passenger.Api/appsettings.json
index d34c659..bfb3e63 100644
--- a/src/Services/Passenger/src/Passenger.Api/appsettings.json
+++ b/src/Services/Passenger/src/Passenger.Api/appsettings.json
@@ -15,14 +15,9 @@
"UserName": "guest",
"Password": "guest"
},
- "Serilog": {
- "MinimumLevel": {
- "Default": "Information",
- "Override": {
- "Microsoft": "Warning",
- "Microsoft.Hosting.Lifetime": "Information"
- }
- }
+ "LogOptions": {
+ "Level": "Information",
+ "LogTemplate": "{Timestamp:HH:mm:ss} [{Level:u4}] {Message:lj}{NewLine}{Exception}"
},
"AllowedHosts": "*"
}