SzymonPobiega / NServiceBus.Router

Cross-transport, cross-site and possibly cross-cloud router component for NServiceBus
MIT License
5 stars 10 forks source link

How to get logged output from the Router #51

Closed chrissmithptml closed 2 years ago

chrissmithptml commented 2 years ago

Howdy, so I have 3 docker containers in my example:

  1. Publisher (SqlTransport) which sends messages / publishes events on a sql isntance
  2. Router Configured to route messages from Sql Transport from the Publisher to Rabbit MQ of my Subscriber
  3. Subscriber (RabbitMQ) which receives messages / events from the Publisher via the Router

Now, having followed every example under the sun and having proved that those examples do work locally, I am still unable to get the Router to route the Events from the Publisher to the Subscriber. Normal messages come through, but no events. I can see the Publisher is publishing the event AND sending the message, but the subscriber only ever gets the message, never the event.

I want to see what's going on with the Router. I want to see its debug output so I can see if the events are even reaching it and/or what's happening with them.

What's the trick to enabling debugging / verbose mode on the router, particularly using the .NET Core Worker Service UseNServiceBusRouter syntax?

Cheers in advance.

chrissmithptml commented 2 years ago

For someone who needs this info. If you're building a .NET 5/6 Worker Host and are using the .UseNServiceBuseRouter syntax to configure your host, you can do the following to get the router to start logging to console etc.

Host.CreateDefaultBuilder(args)
        .UseConsoleLifetime()
        .ConfigureLogging(logging =>
        {
            logging.AddConsole();
            logging.SetMinimumLevel(LogLevel.Information);

            //Add the following lines 
            var nserviceBusLoggingFactory = NServiceBus.Logging.LogManager.Use<NServiceBus.Logging.DefaultFactory>();
            nserviceBusLoggingFactory.Level(NServiceBus.Logging.LogLevel.Debug);

        })
        .UseNServiceBusRouter(ctx =>
        {