feat(logging): Configure Serilog SQLite sink + UI
appsettings.json: - Add Application:LogDirectory configuration - Add Serilog WriteTo.SQLite sink (logs.db in LogDirectory) - Logs table with UTC timestamps Program.cs: - Add Serilog.UI usings - Configure Serilog.UI with SQLite provider - Mount UI at /serilog-ui endpoint Web-based log viewer accessible at: https://localhost:7186/serilog-ui
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
using Serilog;
|
||||
using Serilog.Ui.Core.Extensions;
|
||||
using Serilog.Ui.SqliteDataProvider.Extensions;
|
||||
using Serilog.Ui.Web.Extensions;
|
||||
using DocumentOperator.Infrastructure.Configuration;
|
||||
using DocumentOperator.Application;
|
||||
using DocumentOperator.Infrastructure;
|
||||
@@ -45,7 +48,23 @@ try
|
||||
builder.Services.AddSwaggerDocumentation();
|
||||
|
||||
// ========================================
|
||||
// 4. Build App
|
||||
// 4. Serilog.UI Configuration
|
||||
// ========================================
|
||||
var logDirectory = builder.Configuration.GetValue<string>("Application:LogDirectory")
|
||||
?? throw new InvalidOperationException("Application:LogDirectory not found in configuration.");
|
||||
var sqliteDbPath = Path.Combine(logDirectory, "logs.db");
|
||||
|
||||
builder.Services.AddSerilogUi(logUIOpt =>
|
||||
{
|
||||
logUIOpt.UseSqliteServer(dbOpt =>
|
||||
{
|
||||
dbOpt.WithConnectionString($"Data Source={sqliteDbPath}");
|
||||
dbOpt.WithTable("Logs");
|
||||
});
|
||||
});
|
||||
|
||||
// ========================================
|
||||
// 5. Build App
|
||||
// ========================================
|
||||
var app = builder.Build();
|
||||
|
||||
@@ -67,7 +86,12 @@ try
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
// ========================================
|
||||
// 6. Endpoints (Controller-based API)
|
||||
// 6. Serilog.UI Dashboard
|
||||
// ========================================
|
||||
app.UseSerilogUi(); // Accessible at /serilog-ui
|
||||
|
||||
// ========================================
|
||||
// 7. Endpoints (Controller-based API)
|
||||
// ========================================
|
||||
app.MapControllers(); // Maps all [ApiController] controllers
|
||||
|
||||
|
||||
Reference in New Issue
Block a user