From a9f6c932dbf6216ced7e2c8fce46cb8e665d68ae Mon Sep 17 00:00:00 2001 From: Ricardo Carneiro Date: Thu, 30 Apr 2026 20:19:24 -0300 Subject: [PATCH] fix: log com tenants --- src/BCards.Web/Program.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/BCards.Web/Program.cs b/src/BCards.Web/Program.cs index 3caee33..630c8c2 100644 --- a/src/BCards.Web/Program.cs +++ b/src/BCards.Web/Program.cs @@ -35,13 +35,16 @@ Serilog.Debugging.SelfLog.Enable(msg => System.Diagnostics.Debug.WriteLine($"[SERILOG SELF] {msg}"); }); +var tenantName = builder.Configuration["Tenant:SiteName"] ?? "BCards"; + var loggerConfig = new LoggerConfiguration() .ReadFrom.Configuration(builder.Configuration) .Enrich.FromLogContext() .Enrich.WithEnvironmentName() .Enrich.WithProcessId() .Enrich.WithThreadId() - .Enrich.WithProperty("ApplicationName", builder.Configuration["ApplicationName"] ?? "BCards") + .Enrich.WithProperty("ApplicationName", tenantName) + .Enrich.WithProperty("Tenant", tenantName) .Enrich.WithProperty("Environment", builder.Environment.EnvironmentName) .Enrich.WithProperty("Hostname", hostname); @@ -68,8 +71,9 @@ if (isDevelopment) var openSearchUrl = builder.Configuration["Serilog:OpenSearchUrl"]; if (!string.IsNullOrEmpty(openSearchUrl)) { - var indexFormat = "b-cards-dev-{0:yyyy-MM}"; - Console.WriteLine($"[OPENSEARCH DEV] Configurando sink → {openSearchUrl}"); + var tenantSlug = tenantName.ToLower().Replace("+", "").Replace(" ", "-"); + var indexFormat = $"{tenantSlug}-dev-{{0:yyyy-MM}}"; + Console.WriteLine($"[OPENSEARCH DEV] Configurando sink → {openSearchUrl} (index: {indexFormat})"); // TODO: após confirmar que conecta, restaurar try/catch silencioso (opcional) loggerConfig.WriteTo.Async(a => a.OpenSearch(new OpenSearchSinkOptions(new Uri(openSearchUrl)) @@ -133,7 +137,8 @@ else _ => environment }; - var indexFormat = $"b-cards-{envMapping}-{{0:yyyy-MM}}"; + var tenantSlugProd = tenantName.ToLower().Replace("+", "").Replace(" ", "-"); + var indexFormat = $"{tenantSlugProd}-{envMapping}-{{0:yyyy-MM}}"; try {