pardahlman / RawRabbit

A modern .NET framework for communication over RabbitMq
MIT License
747 stars 144 forks source link

How can I set it to use Serilog while using a connection string? -1.10.3 #221

Closed arrkaye closed 7 years ago

arrkaye commented 7 years ago

Am using: return BusClientFactory.CreateDefault(ConnectionStringParser.Parse(_configurationProvider.CommunicationOptions.ConnectionString));

I'm not sure how to inject Serilog. Please can you advise?

Thanks.

pardahlman commented 7 years ago

Hello @riazkarim - thanks for reporting this!

You could register the RawRabbitConfiguration in the Action<IServiceCollection>. Here's a snippet I've using to that end

public class RawRabbitFactory
{
    public static IBusClient GetDefaultBusClient(string connectionStrName = "RabbitMq", Action<IServiceCollection> overrides = null)
    {
        var config = ExtractConfigFromConnectionString(connectionStrName); // uses ConnectionStringParser
        overrides = overrides ?? (collection => { });
        overrides += collection => collection.AddSingleton(typeof(RawRabbitConfiguration), p => config);
        return BusClientFactory.CreateDefault(overrides);
    }
}

This, then, can be used like below.

RawRabbitFactory.GetDefaultBusClient(
  "RabbitMq",
  ioc => ioc.AddSingleton<ILoggerFactory, LoggerFactory>()
);

Hope this helps!

pardahlman commented 7 years ago

I'll close this for now. Feel free to re-open if the problem isn't solved!

arrkaye commented 7 years ago

Thanks! That worked.