ArieGato / serilog-sinks-rabbitmq

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

Add information on how to configure the sink via appsettings.json #95

Closed irkush closed 4 years ago

irkush commented 4 years ago

Hi!

I have been trying to get the RabbitMQ sink to work for a couple of hours with the configuration done via appsettings.json.

The sink worked perfectly except the fact that I could not change how the logmessage was formatted.

I found the closed issue #89 which pushed me in the right direction. However I needed to pull the code and manually debug why my custom formatter wasn't used as the nuget-package just wouldn't work.

It turned out that the formatter was not configured like the other sinks I use.

So in order to save someone else a few hours I thought that the syntax for how to configure the sink via appsettings.json should be in the readme.md.

Here is how I got it to work:


        "Name": "RabbitMQ",
        "Args": {
          "sinkConfiguration": {
            "BatchPostingLimit": 300
          },
          "textFormatter": "Serilog.Formatting.Json.JsonFormatter",
          "clientConfiguration": {
            "Hostnames": [
              "127.0.0.1"
            ],
            "Exchange": "log_events",
            "ExchangeType": "direct",
            "DeliveryMode": "Durable",
            "RouteKey": "logs",
            "Port": 5672,
            "Password": "guest",
            "Username": "guest"
          }
        }
      }```
madslyng commented 4 years ago

It turned out that the formatter was not configured like the other sinks I use.

What behavior are you used to experiencing ?

I agree the documentation on this way of configuring is not good enough. I'll look into that.

madslyng commented 4 years ago

I don't have time to work on this - so if someone has time to improve the documentation, please create a PR.

irkush commented 4 years ago

Hi!

Sorry for the late reply. I didn't see the question. Here is an example from how the File-sink is configured.

"Name": "File",
"Args": {
  "path": "C:\\application\\log-.log",
  "formatter": "NameSpace.MyFormatter, NameSpace.Common",
  "retainedFileCountLimit": "7",
  "rollingInterval": "Day"
}
},

If possible, it would be nice to change so that the variables are named in the same way as other sinks so that it is easier to add new sinks.

As an example, change the variable textFormatter to be named formatter in the Sink.

madslyng commented 4 years ago

@irkush I'm not going to change the name of the property to align with other sinks, because that will be an unnecessary breaking change, that doesn't really address any real problem. I agree it's not perfect that the naming differs from other sinks - but in terms of configuration convention it's very clear how it works.

I'll work on improving the documentation as we have already talked about.

madslyng commented 4 years ago

Enhancement to documentation should cover sink-configuration based on .config files.