From bfcb0d880ff1086acb8b8ea1f83c58b463d487b7 Mon Sep 17 00:00:00 2001 From: masoud Date: Fri, 5 Dec 2025 19:32:28 +0000 Subject: [PATCH] feat: Read Seq logging config from appsettings.json + add Console logging --- src/CMSMicroservice.WebApi/Program.cs | 11 ++++++++--- src/CMSMicroservice.WebApi/appsettings.json | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/CMSMicroservice.WebApi/Program.cs b/src/CMSMicroservice.WebApi/Program.cs index d81ca18..53e0f1b 100644 --- a/src/CMSMicroservice.WebApi/Program.cs +++ b/src/CMSMicroservice.WebApi/Program.cs @@ -15,8 +15,13 @@ using Hangfire.SqlServer; var builder = WebApplication.CreateBuilder(args); var levelSwitch = new LoggingLevelSwitch(); + +// Read Seq configuration from appsettings.json +var seqServerUrl = builder.Configuration["Seq:ServerUrl"] ?? "http://seq-svc:5341"; +var seqApiKey = builder.Configuration["Seq:ApiKey"]; + var logger = new LoggerConfiguration() - //.WriteTo.Console() + .WriteTo.Console() //.WriteTo.MSSqlServer(builder.Configuration.GetConnectionString("LogConnection"), // sinkOptions: new MSSqlServerSinkOptions // { @@ -24,8 +29,8 @@ var logger = new LoggerConfiguration() // SchemaName = "Log", // AutoCreateSqlTable = true // }) - .WriteTo.Seq("https://seq.afrino.co", - apiKey: "oxpvpUzU1pZxMS4s3Fqq", + .WriteTo.Seq(seqServerUrl, + apiKey: string.IsNullOrEmpty(seqApiKey) ? null : seqApiKey, controlLevelSwitch: levelSwitch) .CreateLogger(); builder.Logging.AddSerilog(logger); diff --git a/src/CMSMicroservice.WebApi/appsettings.json b/src/CMSMicroservice.WebApi/appsettings.json index 9a8f007..e24fe4f 100644 --- a/src/CMSMicroservice.WebApi/appsettings.json +++ b/src/CMSMicroservice.WebApi/appsettings.json @@ -53,5 +53,9 @@ "Authentication": { "Authority": "https://ids.domain.com/", "Audience": "domain_api" + }, + "Seq": { + "ServerUrl": "http://seq-svc:5341", + "ApiKey": "" } }