You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description of the problem, including expected versus actual behavior:
Steps to reproduce:
Use ASP.NET Core with authentication and ClaimsIdentity (e.g. a user is logged in)
The user claims are not included in the ecs output
Cause:
The logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(PropertyName, r)); in the HttpContextEnricher doesn't store the raw object, instead the default propertyFactory does a .ToString() of the r-value, which makes the value of the property: Elastic.CommonSchema.Serilog.HttpContextEnricher,Elastic.CommonSchema.Serilog instead or the original object. In the LogEventConverter, the object cannot be retrieved in (for example) the GetUser method
if(e.TryGetScalarPropertyValue(SpecialKeys.HttpContext,outvar httpContext)&& httpContext.Value is HttpContextEnricher.HttpContextEnrichments enriched)// httpContext.Value is a string!!return enriched.User;// <-- never returned
This causes that the reported user is always the environment user instead of the user doing the request.
builder.Host.UseSerilog((ctx,config)=>{// Ensure HttpContextAccessor is accessiblevarhttpAccessor= ctx.Configuration.Get<HttpContextAccessor>(); config.ReadFrom.Configuration(ctx.Configuration)//.Enrich.WithEcsHttpContext(httpAccessor) <-- this is the unpatched code.Enrich.With(new PatchedHttpContextEnricher(httpAccessor));});
The text was updated successfully, but these errors were encountered:
ECS integration/library project(s): Elastic.CommonSchema.Serilog 8.6.1, Serilog 3.1.1
ECS .NET assembly version (e.g. 1.4.2): 8.6.1
.NET framework / OS: .NET 6 / Windows 11
Description of the problem, including expected versus actual behavior:
Steps to reproduce:
Cause:
The
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(PropertyName, r));
in theHttpContextEnricher
doesn't store the raw object, instead the defaultpropertyFactory
does a.ToString()
of ther
-value, which makes the value of the property:Elastic.CommonSchema.Serilog.HttpContextEnricher,Elastic.CommonSchema.Serilog
instead or the original object. In theLogEventConverter
, the object cannot be retrieved in (for example) theGetUser
methodThis causes that the reported user is always the environment user instead of the user doing the request.
A workaround is to override the enricher:
The text was updated successfully, but these errors were encountered: