ArieGato / serilog-sinks-rabbitmq

Serilog Sink for RabbitMq
Apache License 2.0
54 stars 52 forks source link

not picking any configuration from the appsetting #79

Closed vpoorshab closed 5 years ago

vpoorshab commented 5 years ago

I am using a .net core web application when updating the serilog.sink.rabitmq to v3.0.0 the sink is not picking the configuration from the appsettings, I tried to adjust the setting with the new(breaking) change in version 3, I could not find any explicit guide how version 3 should be set up in appsettings.json so I tried the nested configuration according to https://github.com/serilog/serilog-settings-configuration#nested-configuration-sections but get an exception, is there any way to add configuration settings in the appsettings.json or it should be manually set up in the code?

working settings with version 2

"WriteTo": [{ "Name": "RabbitMQ", "Args": { "Hostname": "", "Username": "", "Password": "", "Exchange": "", "ExchangeType": "", "DeliveryMode": "", "Port": 5672, "Formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact", "restrictedToMinimumLevel": "Warning" } }]

new setting according to version 3 changes

"WriteTo": [{ "Name": "RabbitMQ", "Args": { "configure": [ { "Name": "RabbitMQClientConfiguration", "Args": { "Hostnames": [ "" ], "Username": "", "Password": "", "Exchange": "", "ExchangeType": "", "DeliveryMode": "", "Port": } }, { "Name": "RabbitMQSinkConfiguration", "Args": { "textFormatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact", "restrictedToMinimumLevel": "Warning" } } ] } }]

Startup.cs loggerConfiguration.Enrich.FromLogContext().ReadFrom.Configuration(Configuration);

the exception Cannot create instance of type 'System.Action2[Serilog.Sinks.RabbitMQ.Sinks.RabbitMQ.RabbitMQClientConfiguration,Serilog.Sinks.RabbitMQ.Sinks.RabbitMQ.RabbitMQSinkConfiguration]' because it is missing a public parameterless constructor.

Stack trace

at Microsoft.Extensions.Configuration.ConfigurationBinder.CreateInstance(Type type) at Microsoft.Extensions.Configuration.ConfigurationBinder.BindInstance(Type type, Object instance, IConfiguration config, BinderOptions options) at Microsoft.Extensions.Configuration.ConfigurationBinder.Get(IConfiguration configuration, Type type, Action1 configureOptions) at Microsoft.Extensions.Configuration.ConfigurationBinder.Get(IConfiguration configuration, Type type) at Serilog.Settings.Configuration.ConfigurationReader.<>c__DisplayClass20_0.<CallConfigurationMethods>b__3(<>f__AnonymousType72 <>hTransparentIdentifier0) at System.Linq.Utilities.<>cDisplayClass2_03.<CombineSelectors>b__0(TSource x) at System.Linq.Enumerable.SelectListPartitionIterator2.ToList() at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at Serilog.Settings.Configuration.ConfigurationReader.CallConfigurationMethods(ILookup2 methods, IList1 configurationMethods, Object receiver, IReadOnlyDictionary2 declaredLevelSwitches) at Serilog.Settings.Configuration.ConfigurationReader.Configure(LoggerConfiguration loggerConfiguration) at Serilog.Configuration.LoggerSettingsConfiguration.Settings(ILoggerSettings settings) in C:\projects\serilog\src\Serilog\Configuration\LoggerSettingsConfiguration.cs:line 44 at Nuvei.App.MD.WebApi.Program.<>c.b__1_1(WebHostBuilderContext hostingContext, LoggerConfiguration loggerConfiguration) in

huan086 commented 5 years ago

I think we broke that functionality @tsvetelintsonev. Not sure how to make it compatible, since I don't use serilog-settings-configuration

tsvetelintsonev commented 5 years ago

@huan086 Yes, we definitely have broken this functionality. I will repro this later today. I hope that adding a parameterless constructor to RabbitMQSinkConfiguration will fix it.