ecs-dotnet icon indicating copy to clipboard operation
ecs-dotnet copied to clipboard

[BUG] Missing mutiple fields when use `Serilog.Sinks.Async` library

Open changemyminds opened this issue 2 years ago • 1 comments

ECS integration/library project(s) (e.g. Elastic.CommonSchema.Serilog): aspnetcore-with-serilog

ECS schema version (e.g. 1.4.0): 1.6.0

ECS .NET assembly version (e.g. 1.4.2): 1.5.3

Elasticsearch version (if applicable):

.NET framework / OS: Windows10

Description of the problem, including expected versus actual behavior: I use the project aspnetcore-with-serilog and add Serilog.Sinks.Async library to integrate. I found the HTTP, URL Fields etc... are missing on console.

p.s: Why I need Serilog.Sinks.Async library? Because in my real case, I need write log to file and want to high performance . So I use example project to test.

Steps to reproduce:

  1. Install Serilog.Sinks.Async
dotnet add AspnetCoreExample.csproj package Serilog.Sinks.Async
  1. Modify the Program.cs. Change config.WriteTo.Console(formatter) to config.WriteTo.Async(a => a.Console(formatter))
.UseSerilog((ctx, config) =>
{
	// ... same
	
	// Write events to the console using this configration
	var formatter = new EcsTextFormatter(formatterConfig);

	// use Async	
	config.WriteTo.Async(a => a.Console(formatter));
	
	// mark original sync
	//config.WriteTo.Console(formatter);
})
  1. Use curl to test, see the result.
curl http://localhost:5000/weatherforecast
  • When use the config.WriteTo.Console(formatter) everything workfine.
{"@timestamp":"2022-06-11T00:07:18.1663433+08:00","log.level":"Information","message":"Request starting HTTP/1.1 GET http://localhost:5000/weatherforecast - -","metadata":{"message_template":"{HostingRequestStartingLog:l}","protocol":"HTTP/1.1","method":"GET","content_type":null,"content_length":null,"scheme":"http","path_base":"","path":"/weatherforecast","query_string":"","hosting_request_starting_log":"Request starting HTTP/1.1 GET http://localhost:5000/weatherforecast - -","event_id":{"id":1,"name":"RequestStarting"},"request_id":"0HMIAVD5FC3U1:00000002","request_path":"/weatherforecast","connection_id":"0HMIAVD5FC3U1"},"client":{"address":"127.0.0.1","ip":"127.0.0.1"},"ecs":{"version":"1.6.0"},"event":{"created":"2022-06-11T00:07:18.1663433+08:00","severity":2,"timezone":"台北標準時間"},"http":{"request":{"method":"GET"},"response":{"status_code":200}},"log":{"logger":"Microsoft.AspNetCore.Hosting.Diagnostics","original":null},"process":{"thread":{"id":10},"executable":"AspnetCoreExample","name":"AspnetCoreExample","pid":17660},"server":{"address":"localhost:5000","domain":"localhost:5000","ip":"127.0.0.1"},"url":{"domain":"localhost:5000","full":"http://localhost:5000/weatherforecast","original":"/weatherforecast","path":"/weatherforecast","port":5000,"scheme":"http"},"user_agent":{"device":{"name":"Other"},"os":{"family":"Other","full":"Other","version":""},"name":"curl/7.79.1","original":"curl/7.79.1","version":"7.79.1"}}
{"@timestamp":"2022-06-11T00:07:18.3604462+08:00","log.level":"Information","message":"Executing endpoint '\"AspnetCoreExample.Controllers.WeatherForecastController.Get (AspnetCoreExample)\"'","metadata":{"message_template":"Executing endpoint '{EndpointName}'","endpoint_name":"AspnetCoreExample.Controllers.WeatherForecastController.Get (AspnetCoreExample)","event_id":{"name":"ExecutingEndpoint"},"request_id":"0HMIAVD5FC3U1:00000002","request_path":"/weatherforecast","connection_id":"0HMIAVD5FC3U1"},"client":{"address":"127.0.0.1","ip":"127.0.0.1"},"ecs":{"version":"1.6.0"},"event":{"created":"2022-06-11T00:07:18.3604462+08:00","severity":2,"timezone":"台北標準時間"},"http":{"request":{"method":"GET"},"response":{"status_code":200}},"log":{"logger":"Microsoft.AspNetCore.Routing.EndpointMiddleware","original":null},"process":{"thread":{"id":10},"executable":"AspnetCoreExample","name":"AspnetCoreExample","pid":17660},"server":{"domain":"localhost:5000","ip":"127.0.0.1"},"url":{"domain":"localhost:5000","full":"http://localhost:5000/weatherforecast","original":"/weatherforecast","path":"/weatherforecast","port":5000,"scheme":"http"},"user_agent":{"device":{"name":"Other"},"os":{"family":"Other","full":"Other","version":""},"name":"curl/7.79.1","original":"curl/7.79.1","version":"7.79.1"}}
{"@timestamp":"2022-06-11T00:07:18.4172161+08:00","log.level":"Information","message":"Route matched with \"{action = \\\"Get\\\", controller = \\\"WeatherForecast\\\"}\". Executing controller action with signature \"System.Collections.Generic.IEnumerable`1[AspnetCoreExample.WeatherForecast] Get()\" on controller \"AspnetCoreExample.Controllers.WeatherForecastController\" (\"AspnetCoreExample\").","metadata":{"message_template":"Route matched with {RouteData}. Executing controller action with signature {MethodInfo} on controller {Controller} ({AssemblyName}).","route_data":"{action = \"Get\", controller = \"WeatherForecast\"}","method_info":"System.Collections.Generic.IEnumerable`1[AspnetCoreExample.WeatherForecast] Get()","controller":"AspnetCoreExample.Controllers.WeatherForecastController","assembly_name":"AspnetCoreExample","event_id":{"id":3,"name":"ControllerActionExecuting"},"request_id":"0HMIAVD5FC3U1:00000002","request_path":"/weatherforecast","connection_id":"0HMIAVD5FC3U1"},"client":{"address":"127.0.0.1","ip":"127.0.0.1"},"ecs":{"version":"1.6.0"},"event":{"action":"AspnetCoreExample.Controllers.WeatherForecastController.Get (AspnetCoreExample)","created":"2022-06-11T00:07:18.4172161+08:00","id":"bdb34bd9-689b-4392-a3d0-d763cb4a59ab","severity":2,"timezone":"台北標準時間"},"http":{"request":{"method":"GET"},"response":{"status_code":200}},"log":{"logger":"Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker","original":null},"process":{"thread":{"id":10},"executable":"AspnetCoreExample","name":"AspnetCoreExample","pid":17660},"server":{"domain":"localhost:5000","ip":"127.0.0.1"},"url":{"domain":"localhost:5000","full":"http://localhost:5000/weatherforecast","original":"/weatherforecast","path":"/weatherforecast","port":5000,"scheme":"http"},"user_agent":{"device":{"name":"Other"},"os":{"family":"Other","full":"Other","version":""},"name":"curl/7.79.1","original":"curl/7.79.1","version":"7.79.1"}}
{"@timestamp":"2022-06-11T00:07:18.4291716+08:00","log.level":"Information","message":"Executing \"ObjectResult\", writing value of type '\"AspnetCoreExample.WeatherForecast[]\"'.","metadata":{"message_template":"Executing {ObjectResultType}, writing value of type '{Type}'.","object_result_type":"ObjectResult","type":"AspnetCoreExample.WeatherForecast[]","event_id":{"id":1,"name":"ObjectResultExecuting"},"request_id":"0HMIAVD5FC3U1:00000002","request_path":"/weatherforecast","connection_id":"0HMIAVD5FC3U1"},"client":{"address":"127.0.0.1","ip":"127.0.0.1"},"ecs":{"version":"1.6.0"},"event":{"action":"AspnetCoreExample.Controllers.WeatherForecastController.Get (AspnetCoreExample)","created":"2022-06-11T00:07:18.4291716+08:00","id":"bdb34bd9-689b-4392-a3d0-d763cb4a59ab","severity":2,"timezone":"台北標準時間"},"http":{"request":{"method":"GET"},"response":{"status_code":200}},"log":{"logger":"Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor","original":null},"process":{"thread":{"id":10},"executable":"AspnetCoreExample","name":"AspnetCoreExample","pid":17660},"server":{"domain":"localhost:5000","ip":"127.0.0.1"},"url":{"domain":"localhost:5000","full":"http://localhost:5000/weatherforecast","original":"/weatherforecast","path":"/weatherforecast","port":5000,"scheme":"http"},"user_agent":{"device":{"name":"Other"},"os":{"family":"Other","full":"Other","version":""},"name":"curl/7.79.1","original":"curl/7.79.1","version":"7.79.1"}}
{"@timestamp":"2022-06-11T00:07:18.4650176+08:00","log.level":"Information","message":"Executed action \"AspnetCoreExample.Controllers.WeatherForecastController.Get (AspnetCoreExample)\" in 37.9027ms","metadata":{"message_template":"Executed action {ActionName} in {ElapsedMilliseconds}ms","elapsed_milliseconds":37.9027,"event_id":{"id":2,"name":"ActionExecuted"},"request_id":"0HMIAVD5FC3U1:00000002","request_path":"/weatherforecast","connection_id":"0HMIAVD5FC3U1"},"client":{"address":"127.0.0.1","ip":"127.0.0.1"},"ecs":{"version":"1.6.0"},"event":{"action":"AspnetCoreExample.Controllers.WeatherForecastController.Get (AspnetCoreExample)","created":"2022-06-11T00:07:18.4650176+08:00","id":"bdb34bd9-689b-4392-a3d0-d763cb4a59ab","severity":2,"timezone":"台北標準時間"},"http":{"request":{"method":"GET"},"response":{"status_code":200}},"log":{"logger":"Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker","original":null},"process":{"thread":{"id":10},"executable":"AspnetCoreExample","name":"AspnetCoreExample","pid":17660},"server":{"domain":"localhost:5000","ip":"127.0.0.1"},"url":{"domain":"localhost:5000","full":"http://localhost:5000/weatherforecast","original":"/weatherforecast","path":"/weatherforecast","port":5000,"scheme":"http"},"user_agent":{"device":{"name":"Other"},"os":{"family":"Other","full":"Other","version":""},"name":"curl/7.79.1","original":"curl/7.79.1","version":"7.79.1"}}
{"@timestamp":"2022-06-11T00:07:18.4709141+08:00","log.level":"Information","message":"Executed endpoint '\"AspnetCoreExample.Controllers.WeatherForecastController.Get (AspnetCoreExample)\"'","metadata":{"message_template":"Executed endpoint '{EndpointName}'","endpoint_name":"AspnetCoreExample.Controllers.WeatherForecastController.Get (AspnetCoreExample)","event_id":{"id":1,"name":"ExecutedEndpoint"},"request_id":"0HMIAVD5FC3U1:00000002","request_path":"/weatherforecast","connection_id":"0HMIAVD5FC3U1"},"client":{"address":"127.0.0.1","ip":"127.0.0.1"},"ecs":{"version":"1.6.0"},"event":{"created":"2022-06-11T00:07:18.4709141+08:00","severity":2,"timezone":"台北標準時間"},"http":{"request":{"method":"GET"},"response":{"status_code":200}},"log":{"logger":"Microsoft.AspNetCore.Routing.EndpointMiddleware","original":null},"process":{"thread":{"id":10},"executable":"AspnetCoreExample","name":"AspnetCoreExample","pid":17660},"server":{"domain":"localhost:5000","ip":"127.0.0.1"},"url":{"domain":"localhost:5000","full":"http://localhost:5000/weatherforecast","original":"/weatherforecast","path":"/weatherforecast","port":5000,"scheme":"http"},"user_agent":{"device":{"name":"Other"},"os":{"family":"Other","full":"Other","version":""},"name":"curl/7.79.1","original":"curl/7.79.1","version":"7.79.1"}}
{"@timestamp":"2022-06-11T00:07:18.4767414+08:00","log.level":"Information","message":"Request finished HTTP/1.1 GET http://localhost:5000/weatherforecast - - - 200 - application/json;+charset=utf-8 318.9640ms","metadata":{"message_template":"{HostingRequestFinishedLog:l}","elapsed_milliseconds":318.964,"status_code":200,"content_type":"application/json; charset=utf-8","content_length":null,"protocol":"HTTP/1.1","method":"GET","scheme":"http","path_base":"","path":"/weatherforecast","query_string":"","hosting_request_finished_log":"Request finished HTTP/1.1 GET http://localhost:5000/weatherforecast - - - 200 - application/json;+charset=utf-8 318.9640ms","event_id":{"id":2,"name":"RequestFinished"},"request_id":"0HMIAVD5FC3U1:00000002","request_path":"/weatherforecast","connection_id":"0HMIAVD5FC3U1"},"client":{"address":"127.0.0.1","ip":"127.0.0.1"},"ecs":{"version":"1.6.0"},"event":{"created":"2022-06-11T00:07:18.4767414+08:00","severity":2,"timezone":"台北標準時間"},"http":{"request":{"method":"GET"},"response":{"status_code":200}},"log":{"logger":"Microsoft.AspNetCore.Hosting.Diagnostics","original":null},"process":{"thread":{"id":10},"executable":"AspnetCoreExample","name":"AspnetCoreExample","pid":17660},"server":{"address":"localhost:5000","domain":"localhost:5000","ip":"127.0.0.1"},"url":{"domain":"localhost:5000","full":"http://localhost:5000/weatherforecast","original":"/weatherforecast","path":"/weatherforecast","port":5000,"scheme":"http"},"user_agent":{"device":{"name":"Other"},"os":{"family":"Other","full":"Other","version":""},"name":"curl/7.79.1","original":"curl/7.79.1","version":"7.79.1"}}
  • When use the config.WriteTo.Async(a => a.Console(formatter)) multiple fields is gone.
{"@timestamp":"2022-06-11T00:04:20.019522+08:00","log.level":"Information","message":"Request starting HTTP/1.1 GET http://localhost:5000/weatherforecast - -","metadata":{"message_template":"{HostingRequestStartingLog:l}","protocol":"HTTP/1.1","method":"GET","content_type":null,"content_length":null,"scheme":"http","path_base":"","path":"/weatherforecast","query_string":"","hosting_request_starting_log":"Request starting HTTP/1.1 GET http://localhost:5000/weatherforecast - -","event_id":{"id":1,"name":"RequestStarting"},"request_id":"0HMIAVBGCGUJC:00000002","request_path":"/weatherforecast","connection_id":"0HMIAVBGCGUJC"},"ecs":{"version":"1.6.0"},"event":{"created":"2022-06-11T00:04:20.019522+08:00","severity":2,"timezone":"台北標準時間"},"log":{"logger":"Microsoft.AspNetCore.Hosting.Diagnostics","original":null},"process":{"thread":{"id":6},"executable":"AspnetCoreExample","name":"AspnetCoreExample","pid":20016},"server":{"address":"localhost:5000"}}
{"@timestamp":"2022-06-11T00:04:20.0456893+08:00","log.level":"Information","message":"Executing endpoint '\"AspnetCoreExample.Controllers.WeatherForecastController.Get (AspnetCoreExample)\"'","metadata":{"message_template":"Executing endpoint '{EndpointName}'","endpoint_name":"AspnetCoreExample.Controllers.WeatherForecastController.Get (AspnetCoreExample)","event_id":{"name":"ExecutingEndpoint"},"request_id":"0HMIAVBGCGUJC:00000002","request_path":"/weatherforecast","connection_id":"0HMIAVBGCGUJC"},"ecs":{"version":"1.6.0"},"event":{"created":"2022-06-11T00:04:20.0456893+08:00","severity":2,"timezone":"台北標準時間"},"log":{"logger":"Microsoft.AspNetCore.Routing.EndpointMiddleware","original":null},"process":{"thread":{"id":6},"executable":"AspnetCoreExample","name":"AspnetCoreExample","pid":20016},"server":{}}
{"@timestamp":"2022-06-11T00:04:20.0768831+08:00","log.level":"Information","message":"Route matched with \"{action = \\\"Get\\\", controller = \\\"WeatherForecast\\\"}\". Executing controller action with signature \"System.Collections.Generic.IEnumerable`1[AspnetCoreExample.WeatherForecast] Get()\" on controller \"AspnetCoreExample.Controllers.WeatherForecastController\" (\"AspnetCoreExample\").","metadata":{"message_template":"Route matched with {RouteData}. Executing controller action with signature {MethodInfo} on controller {Controller} ({AssemblyName}).","route_data":"{action = \"Get\", controller = \"WeatherForecast\"}","method_info":"System.Collections.Generic.IEnumerable`1[AspnetCoreExample.WeatherForecast] Get()","controller":"AspnetCoreExample.Controllers.WeatherForecastController","assembly_name":"AspnetCoreExample","event_id":{"id":3,"name":"ControllerActionExecuting"},"request_id":"0HMIAVBGCGUJC:00000002","request_path":"/weatherforecast","connection_id":"0HMIAVBGCGUJC"},"ecs":{"version":"1.6.0"},"event":{"action":"AspnetCoreExample.Controllers.WeatherForecastController.Get (AspnetCoreExample)","created":"2022-06-11T00:04:20.0768831+08:00","id":"82d8d77f-9d63-486d-bfba-f1bcd5c00040","severity":2,"timezone":"台北標 準時間"},"log":{"logger":"Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker","original":null},"process":{"thread":{"id":6},"executable":"AspnetCoreExample","name":"AspnetCoreExample","pid":20016},"server":{}}
{"@timestamp":"2022-06-11T00:04:20.0830647+08:00","log.level":"Information","message":"Executing \"ObjectResult\", writing value of type '\"AspnetCoreExample.WeatherForecast[]\"'.","metadata":{"message_template":"Executing {ObjectResultType}, writing value of type '{Type}'.","object_result_type":"ObjectResult","type":"AspnetCoreExample.WeatherForecast[]","event_id":{"id":1,"name":"ObjectResultExecuting"},"request_id":"0HMIAVBGCGUJC:00000002","request_path":"/weatherforecast","connection_id":"0HMIAVBGCGUJC"},"ecs":{"version":"1.6.0"},"event":{"action":"AspnetCoreExample.Controllers.WeatherForecastController.Get (AspnetCoreExample)","created":"2022-06-11T00:04:20.0830647+08:00","id":"82d8d77f-9d63-486d-bfba-f1bcd5c00040","severity":2,"timezone":"台北標準時間"},"log":{"logger":"Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor","original":null},"process":{"thread":{"id":6},"executable":"AspnetCoreExample","name":"AspnetCoreExample","pid":20016},"server":{}}
{"@timestamp":"2022-06-11T00:04:20.1013301+08:00","log.level":"Information","message":"Executed action \"AspnetCoreExample.Controllers.WeatherForecastController.Get (AspnetCoreExample)\" in 19.72ms","metadata":{"message_template":"Executed action {ActionName} in {ElapsedMilliseconds}ms","elapsed_milliseconds":19.72,"event_id":{"id":2,"name":"ActionExecuted"},"request_id":"0HMIAVBGCGUJC:00000002","request_path":"/weatherforecast","connection_id":"0HMIAVBGCGUJC"},"ecs":{"version":"1.6.0"},"event":{"action":"AspnetCoreExample.Controllers.WeatherForecastController.Get (AspnetCoreExample)","created":"2022-06-11T00:04:20.1013301+08:00","id":"82d8d77f-9d63-486d-bfba-f1bcd5c00040","severity":2,"timezone":"台北標準時間"},"log":{"logger":"Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker","original":null},"process":{"thread":{"id":6},"executable":"AspnetCoreExample","name":"AspnetCoreExample","pid":20016},"server":{}}
{"@timestamp":"2022-06-11T00:04:20.1017481+08:00","log.level":"Information","message":"Executed endpoint '\"AspnetCoreExample.Controllers.WeatherForecastController.Get (AspnetCoreExample)\"'","metadata":{"message_template":"Executed endpoint '{EndpointName}'","endpoint_name":"AspnetCoreExample.Controllers.WeatherForecastController.Get (AspnetCoreExample)","event_id":{"id":1,"name":"ExecutedEndpoint"},"request_id":"0HMIAVBGCGUJC:00000002","request_path":"/weatherforecast","connection_id":"0HMIAVBGCGUJC"},"ecs":{"version":"1.6.0"},"event":{"created":"2022-06-11T00:04:20.1017481+08:00","severity":2,"timezone":"台北標準 時間"},"log":{"logger":"Microsoft.AspNetCore.Routing.EndpointMiddleware","original":null},"process":{"thread":{"id":6},"executable":"AspnetCoreExample","name":"AspnetCoreExample","pid":20016},"server":{}}
{"@timestamp":"2022-06-11T00:04:20.1028962+08:00","log.level":"Information","message":"Request finished HTTP/1.1 GET http://localhost:5000/weatherforecast - - - 200 - application/json;+charset=utf-8 91.5355ms","metadata":{"message_template":"{HostingRequestFinishedLog:l}","elapsed_milliseconds":91.5355,"status_code":200,"content_type":"application/json; charset=utf-8","content_length":null,"protocol":"HTTP/1.1","method":"GET","scheme":"http","path_base":"","path":"/weatherforecast","query_string":"","hosting_request_finished_log":"Request finished HTTP/1.1 GET http://localhost:5000/weatherforecast - - - 200 - application/json;+charset=utf-8 91.5355ms","event_id":{"id":2,"name":"RequestFinished"},"request_id":"0HMIAVBGCGUJC:00000002","request_path":"/weatherforecast","connection_id":"0HMIAVBGCGUJC"},"ecs":{"version":"1.6.0"},"event":{"created":"2022-06-11T00:04:20.1028962+08:00","severity":2,"timezone":"台北標準時間"},"log":{"logger":"Microsoft.AspNetCore.Hosting.Diagnostics","original":null},"process":{"thread":{"id":6},"executable":"AspnetCoreExample","name":"AspnetCoreExample","pid":20016},"server":{"address":"localhost:5000"}}

This problem is using Serilog.Sinks.Async library that cause the configuration.MapHttpAdapter properties to be null.

changemyminds avatar Jun 10 '22 16:06 changemyminds

We have also encountered this same issue.

Serilog.Sinks.Async causes the logging to happen on a background thread, but IHttpContextAccessor is not thread safe and "may be null if accessed outside of the request flow" (https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-context?view=aspnetcore-6.0#httpcontext-isnt-thread-safe) - which appears to be the cause of this bug, where HttpAdapter is unable to map the fields because _httpContextAccessor.HttpContext is null.

adamf-datapath avatar Sep 12 '22 11:09 adamf-datapath

I also encountered this problem. I bypassed it by creating a new HttpContextEnricher that completes LogEvent with the information contained in the HTTP context. The LogEventConverter is asynchronous => problem Enrichers are synchronous = > solution

using Elastic.CommonSchema.Serilog.Extensions;
using Elastic.CommonSchema.Serilog.Http;
#if NETSTANDARD
using Microsoft.AspNetCore.Http;
#endif
using Serilog.Core;
using Serilog.Events;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;

namespace Elastic.CommonSchema.Serilog.Enrichers
{
    public class HttpContextEnricher : ILogEventEnricher
    {

#if NETSTANDARD


        private readonly IHttpContextAccessor _httpContextAccessor;

        public HttpContextEnricher(IHttpContextAccessor httpContextAccessor) =>
            _httpContextAccessor = httpContextAccessor;

        public IHttpAdapter Adapter
        {
            get
            {
                return new HttpAdapter(_httpContextAccessor);
            }
        }
#else



        public IHttpAdapter Adapter
        {
            get
            {
                return new HttpAdapter();
            }
        }
#endif


        /// <summary>
        /// The property name added to enriched log events.
        /// </summary>
        public const string PropertyName = SpecialKeys.HttpContext;

        /// <summary>
        /// Enrich the log event.
        /// </summary>
        /// <param name="logEvent">The log event to enrich.</param>
        /// <param name="propertyFactory">Factory for creating new properties to add to the event.</param>
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            // Don't care about thread-safety, in the worst case the field gets overwritten and one
            // property will be GCed
            var r = new HttpContextEnrichements();
            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;
            }

            logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(PropertyName, r.ToJson()));
        }




    }


}

using System;
using System.Collections.Generic;
using System.Text;

namespace Elastic.CommonSchema.Serilog.Http
{
    public class HttpContextEnrichements

    {
        public Client Client { get; set; }
        public CommonSchema.Http Http { get; set; }
        public Server Server { get; set; }
        public Url Url { get; set; }
        public User User { get; set; }
        public UserAgent UserAgent { get; set; }
    }
}

nicocomumu avatar Dec 29 '22 10:12 nicocomumu

Thanks @nicocomumu for taking the time to list your approach.

I opened https://github.com/elastic/ecs-dotnet/pull/257 to fix this issue using a synchronous enricher.

Thanks @changemyminds for bringing this to our attention!

Mpdreamz avatar Feb 09 '23 10:02 Mpdreamz