ArieGato / serilog-sinks-rabbitmq

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

Add support for dynamic routing keys #104

Closed maxdeviant closed 6 months ago

maxdeviant commented 4 years ago

Is your feature request related to a problem? Please describe.

At my job we currently have a RabbitMQ-based logging infrastructure that routes messages to different log files based on the RabbitMQ routing key. In our case we use a routing key in the following form: CATEGORY.ACTION.LEVEL.

This allow us to use routing key filters to route certain messages to certain log files. For example:

Describe the solution you'd like

I would like to be able to customize the routing key for the RabbitMQ message based on the log event.

As part of the sink configuration you would optionally provide a way to build a routing key from a LogEvent, which would then be used when publishing the message.

If no dynamic routing key is provided then we would still use the static RouteKey specified in the sink configuration.

Describe alternatives you've considered

The lack of support for dynamic routing keys could probably be worked around by creating a bunch of different loggers all configured with different routing keys and then logging to the desired one.

However, I don't think this is an ideal solution, as it is much harder to setup all of the individual loggers and then have to ensure that you are logging with the correct logger. Additionally, this doesn't work well when hooking into ASP.NET Core's existing logging infrastructure.

Additional context

I would be happy to implement this feature.

madslyng commented 4 years ago

https://github.com/steffenlyng/serilog-sinks-rabbitmq/tree/feature/103_add-support-for-dynamic-routing-keys

Needs tests before it will be included in the next release.