serilog / serilog-settings-configuration

A Serilog configuration provider that reads from Microsoft.Extensions.Configuration
Apache License 2.0
456 stars 129 forks source link

Expression Template not working #298

Closed PatrikBak closed 2 years ago

PatrikBak commented 2 years ago

I tried the code from the documentation:

{
  "Name": "Console",
  "Args": {
    "formatter": {
      // `type` (or $type) is optional, must be specified for abstract declared parameter types
      "type": "Serilog.Templates.ExpressionTemplate, Serilog.Expressions",
      "template": "[{@t:HH:mm:ss} {@l:u3} {Coalesce(SourceContext, '<none>')}] {@m}\n{@x}"
  }
}

(a) It misses one curly bracket (b) More importantly, it won't work:

Unhandled exception. System.InvalidOperationException: Cannot create instance of type 'Serilog.Formatting.ITextFormatter' because it is either abstract or an interface.
   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, Action`1 configureOptions)
   at Microsoft.Extensions.Configuration.ConfigurationBinder.Get(IConfiguration configuration, Type type)
   at Serilog.Settings.Configuration.ObjectArgumentValue.ConvertTo(Type toType, ResolutionContext resolutionContext)
   at Serilog.Settings.Configuration.ConfigurationReader.<>c__DisplayClass18_2.<CallConfigurationMethods>b__3(<>f__AnonymousType9`2 <>h__TransparentIdentifier0)
   at System.Linq.Utilities.<>c__DisplayClass2_0`3.<CombineSelectors>b__0(TSource x)
   at System.Linq.Enumerable.SelectListPartitionIterator`2.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Serilog.Settings.Configuration.ConfigurationReader.CallConfigurationMethods(ILookup`2 methods, IList`1 configurationMethods, Object receiver)
   at Serilog.Settings.Configuration.ConfigurationReader.ApplySinks(LoggerConfiguration loggerConfiguration)
   at Serilog.Settings.Configuration.ConfigurationReader.Configure(LoggerConfiguration loggerConfiguration)
   at Serilog.Configuration.LoggerSettingsConfiguration.Settings(ILoggerSettings settings)
   at Serilog.ConfigurationLoggerConfigurationExtensions.Configuration(LoggerSettingsConfiguration settingConfiguration, IConfiguration configuration, String sectionName, DependencyContext dependencyContext)
   at Serilog.ConfigurationLoggerConfigurationExtensions.Configuration(LoggerSettingsConfiguration settingConfiguration, IConfiguration configuration, DependencyContext dependencyContext)
  1. Package Serilog.Expressions is installed with a version of 3.2.1
  2. Adding "Using": [ "Serilog.Expressions" ] doesn't help.

This is for a net5.0 project.

skomis-mm commented 2 years ago

Hi @PatrikBak , what version of the Serilog.Settings.Configuration do you use? Try the last one (3.3.0)

PatrikBak commented 2 years ago

Hi @PatrikBak , what version of the Serilog.Settings.Configuration do you use? Try the last one (3.3.0)

Thank you, my bad :(