Using Rabbitmq and Serilog via appsettings.json

1,622 views
Skip to first unread message

Tom Nieuwenhuis

unread,
Aug 23, 2019, 7:14:14 AM8/23/19
to rabbitmq-users
Hi,

Not sure if my previous questions has reached the group, so I'll try once again.

I'm having some difficulties to hook up RabbitMQ to Serilog, in an ASP.Net Core app.
RabbitMQ works fine directly from C# code (I have some other queues and an exchange working, no problem).
Serilog works fine writing to a File, via appsettings.json.

The combination however, is where my problem lies. I do not succeed in providing the correct settings inside the appsettings.json for Serilog to log to a RabbitMQ exchange / queue.

My appsettings sofar:
{
    "Logging": {
        "LogLevel": {
            "Default": "Debug",
            "System": "Information",
            "Microsoft": "Information"
        }
    },
    "Serilog": {
        "Using": ["Serilog.Sinks.RabbitMQ"],
        "MinimumLevel": "Debug",
        "WriteTo": [
            {
                "Name": "RabbitMQ",
                "Args": {
                    "Hostnames": [ "localhost" ],
                    "Port": 15672,
                    "Exchange": "myExchange",
                    "ExchangeType": "direct",
                    "RouteKey": "logging",
                    "DeliveryMode": "RabbitMQDeliveryMode.Durable"
                }
            },
            {
                "Name": "File",
                "Args": {
                    "path": "MyLogFile_.log",
                    "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}",
                    "rollingInterval": "Day"
                }
            }
        ]
    }
}

I have referenced Serilog.Sinks.RabbitMQ, version 3.0.3
Exchange Binding to Queue is correctly setup, Routing Key is also correct inside RabbitMQ.

I have tried to provide username, password, vhost, and all sorts of casing combinations etc. However, it will not log :-(

The call inside Main is like this, using DI:
_logger.LogInformation("Hooray, I'm started!");

This line is being logged to File correctly, but I also would like to have it logged to RabbitMQ.

Any ideas what I might be doing wrong?

Thanks in advance for your help,
Tom

Tom Nieuwenhuis

unread,
Aug 28, 2019, 3:08:38 AM8/28/19
to rabbitmq-users
Hi,

For those who might have the same or similar question:
The port number was incorrect. Should be 5672 instead of 15672. The latter is only for the Management Plugin to be accessible.

Solved.

Regards,
Tom

Op vrijdag 23 augustus 2019 13:14:14 UTC+2 schreef Tom Nieuwenhuis:
Reply all
Reply to author
Forward
0 new messages