serilog-enrichers-aspnetcore-httpcontext icon indicating copy to clipboard operation
serilog-enrichers-aspnetcore-httpcontext copied to clipboard

Compatibility with Net Core 3.1

Open alexandrejobin opened this issue 5 years ago • 3 comments

The current version doesn't work with .Net Core v3.1. Nothing is parsed in the output.

alexandrejobin avatar Dec 11 '19 18:12 alexandrejobin

It seems that the StandardEnricher function is not called from this line _customAction.Invoke(_httpContextAccessor) in this function but I don't know why:

public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
    HttpContext ctx = _httpContextAccessor.HttpContext;
    if (ctx == null) return;

    var httpContextCache = ctx.Items[$"serilog-enrichers-aspnetcore-httpcontext"];

    if (httpContextCache == null)
    {
        httpContextCache = _customAction.Invoke(_httpContextAccessor);
        ctx.Items[$"serilog-enrichers-aspnetcore-httpcontext"] = httpContextCache;
    }
    logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("HttpContext", httpContextCache, true));             
}

alexandrejobin avatar Dec 11 '19 18:12 alexandrejobin

I would love to see this issue addressed, and also the documentation updated around the configuration, since the hostbuilder stuff changed for v3.

zachrybaker avatar Jul 14 '20 21:07 zachrybaker

I too am unable to get this to work. We need some updated information on how to get this to work with .NET Core 3.1

davesofthunder avatar Aug 10 '20 21:08 davesofthunder