trenoncourt / serilog-enrichers-aspnetcore-httpcontext

Enriches Serilog events with Aspnetcore HttpContext.
MIT License
38 stars 17 forks source link

Compatibility with Net Core 3.1 #11

Open alexandrejobin opened 4 years ago

alexandrejobin commented 4 years ago

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

alexandrejobin commented 4 years ago

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));             
}
zachrybaker commented 4 years ago

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

davesofthunder commented 4 years ago

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