`WriteTo` JSON formatter

I use GitHub - denis-peshkov/Serilog.Enrichers.HttpContext: Enriches Serilog events with client IP, Correlation Id, RequestBody, RequestQuery, HTTP request headers and information of the memory usage. to extract http header values and have the following configuration in appsettings.json:

        "WriteTo": [
            {
                "Name": "Console",
                    "Args": {
                        "outputTemplate": "[{Timestamp}] {Level} {EventId} IP:{ClientIp} CorrelationId:{CorrelationId} Agent:{UserAgent} ContentType:{ContentType} ContentLength:{ContentLength} RequestBody:{RequestBody} RequestQuery:{RequestQuery} MemoryUsage:{MemoryUsageExact}/{MemoryUsage} {Message:j} {Properties} {NewLine}{Exception}{NewLine}",
                        "customFormatter": "Elastic.CommonSchema.Serilog.EcsTextFormatter, Elastic.CommonSchema.Serilog"
                    }
            },

However, the log I get doesn't seem to be json formatted:

[04/21/2025 12:38:02 +08:00] Information { Id: 2, Name: "ResponseLog" } IP:::1 CorrelationId:null Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 ContentType:null ContentLength:null RequestBody: RequestQuery: MemoryUsage:/338575360 Response:
StatusCode: 200
Content-Type: image/x-icon
Accept-Ranges: bytes
ETag: [Redacted]
Last-Modified: Thu, 16 Jun 2022 07:02:55 GMT
Content-Length: 32038 { StatusCode: 200, Content-Type: "image/x-icon", Accept-Ranges: "bytes", ETag: "[Redacted]", Last-Modified: "Thu, 16 Jun 2022 07:02:55 GMT", Content-Length: "32038", SourceContext: "Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware", RequestId: "0HNC0HP5TD59L:00000023", RequestPath: "/favicon.ico", ConnectionId: "0HNC0HP5TD59L", ThreadId: 25, X_Original_For: null, X_Forwarded_Proto: null, X_Original_Proto: null, X_Forwarded_Host: null, X_Original_Host: null } 
[04/21/2025 12:38:02 +08:00] Information { Id: 2 } IP:::1 CorrelationId:null Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 ContentType:image/x-icon ContentLength:32038 RequestBody: RequestQuery: MemoryUsage:/339099648 Request finished "HTTP/2" "GET" "https"://"[::1]:4433""""/favicon.ico""" - 200 32038 "image/x-icon" 10.8386ms { SourceContext: "Microsoft.AspNetCore.Hosting.Diagnostics", RequestId: "0HNC0HP5TD59L:00000023", RequestPath: "/favicon.ico", ConnectionId: "0HNC0HP5TD59L", ThreadId: 13, X_Original_For: null, X_Forwarded_Proto: null, X_Original_Proto: null, X_Forwarded_Host: null, X_Original_Host: null } 

Hi @Kok_How_Teh

The issue is that you're using both outputTemplate and customFormatter together, which may be conflicting. For JSON output, try removing the outputTemplate and use only the formatter like this:

"WriteTo": [
    {
        "Name": "Console",
        "Args": {
            "formatter": "Elastic.CommonSchema.Serilog.EcsTextFormatter, Elastic.CommonSchema.Serilog"
        }
    }
]