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)));
}