serilog-contrib / Serilog.Sinks.Logz.Io

Apache License 2.0
15 stars 11 forks source link

Different casing of property names with LogzIo and LogzIoDurableHttp sinks #29

Closed angularsen closed 1 year ago

angularsen commented 2 years ago

Problem

LogzIo uses camel case properties: @timestamp, level, messageTemplate, exception etc. LogzIoDurableHttp uses pascal case properties: Timestamp, Level, MessageTemplate, Exception etc.

Related to #24, we have been using both the "old" LogzIo sink and the newer durable LogzIoDurableHttp sink. Since logz.io is case-sensitive on property names, we ran into indexing and filtering issues switching between the two sinks.

Solution

Since it is a breaking change for logz.io indexing/filtering, we can't just change the default. We could offer a flag to select casing for both sinks, such as PascalCase vs camelCase. Each sink could then default to their current configuration.

Research

I belive these are the relevant places: https://github.com/serilog-contrib/Serilog.Sinks.Logz.Io/blob/5b0aa2d1bb9a4bf4e080a99ce2b466cd15fb6a48/src/Serilog.Sinks.Logz.Io/LogzioSink.cs#L163-L190

https://github.com/FantasticFiasco/serilog-sinks-http/blob/6af0b5adfa4750c7698780b87008a18c8d542ded/src/Serilog.Sinks.Http/Sinks/Http/TextFormatters/NormalTextFormatter.cs#L66-L97

            output.Write("{\"Timestamp\":\"");
            output.Write(logEvent.Timestamp.UtcDateTime.ToString("o"));

            output.Write("\",\"Level\":\"");
            output.Write(logEvent.Level);

            output.Write("\",\"MessageTemplate\":");
            JsonValueFormatter.WriteQuotedJsonString(logEvent.MessageTemplate.Text, output);

Setups we used

loggerConfig.WriteTo.LogzIo(logzIoToken,
    type: "app",
    dataCenterSubDomain: logzIoSubdomain,
    lowercaseLevel: false,
    includeMessageTemplate: true,
    boostProperties: true);

loggerConfig.WriteTo.LogzIoDurableHttp(logzIoUrl,
    bufferPathFormat: Path.Combine(AppContext.BaseDirectory, "temp", "logzio-buffer-{Date}.json"),
    logzioTextFormatterOptions: new LogzioTextFormatterOptions
    {
        BoostProperties = true,
        IncludeMessageTemplate = true,
        LowercaseLevel = false,
    });
mantasaudickas commented 1 year ago

Should be solved now with 7.1.0