Skip to content

Constructor parameters - support objects with collection properties #314

@sfkoch

Description

@sfkoch

I've been trying to configure Serilog.Sinks.Splunk.EventCollectorSink from appsettings.json, but can't get it to construct the CustomFields object for the "fields" parameter. When I provide an array of 3 CustomField objects, TryBuildCtorExpression is trying and failing to find a constructor for List<CustomField> that takes 3 arguments.

This is the JSON I've tried:

    "WriteTo:EventCollector": {
      "Name": "EventCollector",
      "Args": {
        "splunkHost": "redacted",
        "eventCollectorToken": "redacted",
        "restrictedToMinimumLevel": "Warning",
        "host": "%COMPUTERNAME%",
        "fields": {
          "$type": "Serilog.Sinks.Splunk.CustomFields, Serilog.Sinks.Splunk",
          "customFields": [
            {
              "$type": "Serilog.Sinks.Splunk.CustomField, Serilog.Sinks.Splunk",
              "name": "name1",
              "value": "value1"
            },
            {
              "$type": "Serilog.Sinks.Splunk.CustomField, Serilog.Sinks.Splunk",
              "name": "name2",
              "value": "value2"
            },
            {
              "$type": "Serilog.Sinks.Splunk.CustomField, Serilog.Sinks.Splunk",
              "name": "name3",
              "value": "value3"
            }
          ]
        }
      }
    }

I also tried structuring "fields" for the fallback to ConfigurationBinding.Get in ObjectArgumentValue.ConvertTo, but that failed because CustomField doesn't have a default constructor.

Perhaps TryBuildCtorExpression needs something like TryCreateContainer from ConvertTo for when parameterType is a collection?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions