-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix to allow to set Subject or Body using JSON configuration when usi… #131
base: dev
Are you sure you want to change the base?
Conversation
…ng overload that accepts EmailSinkOptions and PeriodicBatchingSinkOptions
See issue #130 |
@MrPsi I see that your PR didn't make it in the sink email release 4.0.0 |
Thanks for the nudge, I'll loop back to this and take a look ASAP 👍 |
A quick status update; I've dug into this and I think the best option to make a quick fix here is to work out why the "complex type" subject doesn't work: "subject": {
"type": "Serilog.Formatting.Display.MessageTemplateTextFormatter, Serilog",
"outputTemplate": "Serilog test"
}, As I understand it, this should work today with Serilog.Settings.Configuration 8.0.1, but I haven't had any luck either. I spent a while skimming over possible places this could have broken but I think the only way to get to the bottom of it will be to create a test case over there and debug it. On the plus side, though, if we can track down why complex object creation isn't working, we should be able to get the fix out quickly in a small patch. Other approaches, like the one in the PR, would need more time thinking through the API. For example, the proposed change would prevent using an I'll aim to dig into the Serilog.Settings.Configuration side ASAP, but if anyone manages beat me to it, I'd appreciate the help :-) |
Hi, Thanks for looking at this. I did create an issue in the Serilog.Settings.Configuration repository for this, see serilog/serilog-settings-configuration#417 . If I understand the flow in the configuration correctly it will try to find a constructor in the ObjectArgumentValue.ConvertTo method when, for example, it tries to build the EmailSinkOptions. When it does not find any, it will fall back to _section.Get(toType) on line 58. It is only the constructor that supports complex types, hence it will not work. The solutions I see is that, either EmailSinkOptions needs a constructor, or the configuration needs to check if it can set properties on the class when it can not find a constructor. But please double check my findings if you find the time, I might have missed something. |
I updated the PR and changed the type for subject and body in the constructor to ITextFormatter, which is the same type as the properties have.
Hopefully this is more acceptable and will not break the API? |
Fix to allow to set Subject or Body using JSON configuration when using overload that accepts EmailSinkOptions and PeriodicBatchingSinkOptions