From 5080b0710143e0404a6c50e51d2f6142d1353ed7 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Thu, 3 Oct 2024 16:47:06 +0200 Subject: [PATCH] Ensure correct embedded logical name for UParser.regexes.cs (#452) --- .../appsettings.Development.json | 3 ++- .../aspnetcore-with-serilog/appsettings.json | 3 ++- .../Elastic.Serilog.Enrichers.Web.csproj | 2 +- .../HttpContextEnricher.cs | 21 ++++++++++--------- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/examples/aspnetcore-with-serilog/appsettings.Development.json b/examples/aspnetcore-with-serilog/appsettings.Development.json index 8983e0fc..3c5c8eab 100644 --- a/examples/aspnetcore-with-serilog/appsettings.Development.json +++ b/examples/aspnetcore-with-serilog/appsettings.Development.json @@ -3,7 +3,8 @@ "LogLevel": { "Default": "Information", "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" + "Microsoft.Hosting.Lifetime": "Information", + "Elastic.Apm": "Error" } } } diff --git a/examples/aspnetcore-with-serilog/appsettings.json b/examples/aspnetcore-with-serilog/appsettings.json index d9d9a9bf..c1cc9590 100644 --- a/examples/aspnetcore-with-serilog/appsettings.json +++ b/examples/aspnetcore-with-serilog/appsettings.json @@ -3,7 +3,8 @@ "LogLevel": { "Default": "Information", "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" + "Microsoft.Hosting.Lifetime": "Information", + "Elastic.Apm": "Error" } }, "AllowedHosts": "*" diff --git a/src/Elastic.Serilog.Enrichers.Web/Elastic.Serilog.Enrichers.Web.csproj b/src/Elastic.Serilog.Enrichers.Web/Elastic.Serilog.Enrichers.Web.csproj index d507e4b2..4806848b 100644 --- a/src/Elastic.Serilog.Enrichers.Web/Elastic.Serilog.Enrichers.Web.csproj +++ b/src/Elastic.Serilog.Enrichers.Web/Elastic.Serilog.Enrichers.Web.csproj @@ -25,7 +25,7 @@ - + diff --git a/src/Elastic.Serilog.Enrichers.Web/HttpContextEnricher.cs b/src/Elastic.Serilog.Enrichers.Web/HttpContextEnricher.cs index 274a6653..926b9008 100644 --- a/src/Elastic.Serilog.Enrichers.Web/HttpContextEnricher.cs +++ b/src/Elastic.Serilog.Enrichers.Web/HttpContextEnricher.cs @@ -38,16 +38,17 @@ public HttpContextEnricher(IHttpContextAccessor httpContextAccessor) => /// Enrich the log event. public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { - var r = new HttpContextEnrichments(); - if (Adapter.HasContext) - { - r.Http = Adapter.Http; - r.Server = Adapter.Server; - r.Url = Adapter.Url; - r.UserAgent = Adapter.UserAgent; - r.Client = Adapter.Client; - r.User = Adapter.User; - } + if (!Adapter.HasContext) + return; + + var r = new HttpContextEnrichments { + Http = Adapter.Http, + Server = Adapter.Server, + Url = Adapter.Url, + UserAgent = Adapter.UserAgent, + Client = Adapter.Client, + User = Adapter.User + }; logEvent.AddPropertyIfAbsent(new LogEventProperty(PropertyName, new ScalarValue(r))); }