diff --git a/sample/RawRabbit.ConsoleApp.Sample/Program.cs b/sample/RawRabbit.ConsoleApp.Sample/Program.cs index 14a85ab9..d145a82d 100644 --- a/sample/RawRabbit.ConsoleApp.Sample/Program.cs +++ b/sample/RawRabbit.ConsoleApp.Sample/Program.cs @@ -2,10 +2,12 @@ using System.IO; using System.Threading.Tasks; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using RawRabbit.Configuration; using RawRabbit.Enrichers.GlobalExecutionId; using RawRabbit.Enrichers.MessageContext; using RawRabbit.Enrichers.MessageContext.Context; +using RawRabbit.Logging; using RawRabbit.Messages.Sample; using RawRabbit.vNext; using RawRabbit.vNext.Pipe; @@ -32,7 +34,9 @@ public static async Task RunAsync() .Get(), Plugins = p => p .UseGlobalExecutionId() - .UseMessageContext() + .UseMessageContext(), + DependencyInjection = ioc => ioc + .AddSingleton(provider => new LoggerFactory(s => new ConsoleLogger(LogLevel.Debug, s))) }); await _client.SubscribeAsync((requested, ctx) => ServeValuesAsync(requested, ctx)); diff --git a/src/RawRabbit.vNext/AddRawRabbitExtension.cs b/src/RawRabbit.vNext/AddRawRabbitExtension.cs index 51953a30..f34bcca8 100644 --- a/src/RawRabbit.vNext/AddRawRabbitExtension.cs +++ b/src/RawRabbit.vNext/AddRawRabbitExtension.cs @@ -9,9 +9,9 @@ public static class AddRawRabbitExtension { public static IServiceCollection AddRawRabbit(this IServiceCollection collection, RawRabbitOptions options = null) { - options?.DependencyInjection?.Invoke(collection); var adapter = new ServiceCollectionAdapter(collection); adapter.AddRawRabbit(options); + options?.DependencyInjection?.Invoke(collection); return collection; } } diff --git a/src/RawRabbit/DependecyInjection/RawRabbitDependencyRegisterExtension.cs b/src/RawRabbit/DependecyInjection/RawRabbitDependencyRegisterExtension.cs index 62dc4c6f..5535800e 100644 --- a/src/RawRabbit/DependecyInjection/RawRabbitDependencyRegisterExtension.cs +++ b/src/RawRabbit/DependecyInjection/RawRabbitDependencyRegisterExtension.cs @@ -1,5 +1,4 @@ -using System; -using System.Linq; +using System.Linq; using System.Runtime.Serialization.Formatters; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; @@ -36,6 +35,7 @@ public static IDependecyRegister AddRawRabbit(this IDependecyRegister register, .AddSingleton(options?.ClientConfiguration ?? RawRabbitConfiguration.Local) .AddSingleton(provider => { + LogManager.CurrentFactory = provider.GetService(); var cfg = provider.GetService(); return new ConnectionFactory { diff --git a/src/RawRabbit/Instantiation/RawRabbitFactory.cs b/src/RawRabbit/Instantiation/RawRabbitFactory.cs index 6c175880..e6679602 100644 --- a/src/RawRabbit/Instantiation/RawRabbitFactory.cs +++ b/src/RawRabbit/Instantiation/RawRabbitFactory.cs @@ -28,7 +28,6 @@ public static InstanceFactory CreateInstanceFactory(RawRabbitOptions options, ID { register.AddRawRabbit(options); var resolver = resolverFunc(register); - LogManager.CurrentFactory = resolver.GetService(); return new InstanceFactory(resolver); } }