serilog / serilog-settings-configuration

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

Not able to specify complex parameter #417

Closed MrPsi closed 1 week ago

MrPsi commented 4 months ago

Hi,

I am trying to specify a complex parameter for subject and body for Serilog.Sinks.Email like this:

    "WriteTo": [
      {
        "Name": "Email",
        "Args": {
          "options": {
            "subject": {
              "type": "Serilog.Formatting.Display.MessageTemplateTextFormatter, Serilog",
              "outputTemplate": "Serilog test"
            },
            "from": "from@email.com",
            "to": [ "to@email.com" ],
            "host": "localhost",
            "body": {
              "type": "Serilog.Formatting.Display.MessageTemplateTextFormatter, Serilog",
              "outputTemplate": "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message}{NewLine}{Exception}{NewLine}"
            }
          },
          "batchingOptions": {
            "batchSizeLimit": 10,
            "period": "00:00:01"
          },
          "restrictedToMinimumLevel": "Information"
        }
      }
    ]

Unfortunately it doesn't work for subject and body. It works for the other settings. If I add a constructor to the options class, that mirrors the properties, it will work.

Is this expected behavior, or is it a bug? In other words, should this be fixed in Serilog.Settings.Configuration, or in Serilog.Sinks.Email?

Best regards

nblumhardt commented 2 months ago

This seems like a bug, thanks @MrPsi :+1: