ArieGato / serilog-sinks-rabbitmq

Serilog Sink for RabbitMq
Apache License 2.0
56 stars 53 forks source link

Configuration through appsettings - setting custom textformatter #209

Closed Scopla closed 1 month ago

Scopla commented 2 months ago

Hello,

It seems that with the current version of Serilog and the configuration of an alternative text formatter seems to work differently than in the past. I am not sure if I am doing something wrong and something changed over time or if this may be an unintended bug.

In the past I was used to configure the logger in the app settings json like in this example:

"WriteTo": [
  {
    "Name": "RabbitMQ",
    "Args": {
      "sinkConfiguration": {
        "batchPostingLimit": 300,
        "textFormatter": "Serilog.Formatting.Json.JsonFormatter, Serilog",
        "queueLimit": 200
      },
      "clientConfiguration": {
        "hostnames": [ "localhost" ],
        "exchange": "LogExchange",
        "exchangeType": "direct",
        "deliveryMode": "Durable",
        "routeKey": "logging",
        "port": 5672,
        "username": "serilog",
        "password": "serilog"
      }
    }
  }
]

The batchPostingLimit and the queueLimit are set correctly but the textFormatter stays at the default one.

Changing the formatter only works if I am using this format:

"WriteTo": [
  {
    "Name": "RabbitMQ",
    "Args": {
      "batchPostingLimit": 300,
      "formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog",
      "queueLimit": 200,
      "hostnames": [ "localhost" ],
      "exchange": "LogExchange",
      "exchangeType": "direct",
      "deliveryMode": "Durable",
      "routeKey": "logging",
      "port": 5672,
      "username": "serilog",
      "password": "serilog"
    }
  }
]

I tested it with the Net8AppsettingsJsonSample in the repository.

Am I doing something wrong?

ArieGato commented 2 months ago

@Scopla the structure from the sample should be the correct one. You could try an older version of the package and find out in which version the structure changed.

ArieGato commented 1 month ago

@Scopla Is there something I can help you with, or can I close the issue?

Scopla commented 1 month ago

Hi,

thanks for the answer.

I tested a little bit more and found out that it works if I use the dev branch of https://github.com/serilog/serilog-settings-configuration.

If I use the main branch I have the problems. I can share an example next week when I am back home.

ArieGato commented 1 month ago

@Scopla Did you have a chance to create a repo?

Scopla commented 1 month ago

Hi,

yes I had time today: Link to Repo

I hope the readme is enough explanation, if not I will extend it. Basically this formatter is used when using the main branch of Serilog.Settings.Configuration. With the dev branch it uses the JsonFormatter specified in the appsettings. NotParsed

ArieGato commented 1 month ago

@Scopla, Do I understand correctly that you're saying that the sink is not configured correctly when using main branch of Serilog.Settings.Configuration, but is when using the dev branch?

Scopla commented 1 month ago

Yes, exactly. And it seems to affect only the text formatter in this case. The primitive types work fine.

ArieGato commented 1 month ago

Then I assume this is an issue of Serilog.Settings.Configuration which has been fixed already. Or do you suspect an issue in this repo?

ArieGato commented 1 month ago

I think this is the fix: https://github.com/serilog/serilog-settings-configuration/pull/430

ArieGato commented 1 month ago

I can confirm that this was indeed the fix for this issue.

This version fixes the issue: https://www.nuget.org/packages/Serilog.Settings.Configuration/8.0.2-dev-00599. 8.0.2-dev-00598 doesn't set the complex objects correctly.

Scopla commented 1 month ago

Yes, that what i figured out a long the way when investigating the issue. Sorry for not communicating that clearly enough with the previous posts that I already learned that the issue is in the configuration package.

Thanks for the help!

ArieGato commented 1 month ago

@Scopla, Serilog.Settings.Configuration version 8.0.3 has been released, which includes the fix for adding nested complex types to the appsettings.