2

I'm using the Serilog.Extras.AppSetting package, to configure Serilog. I'm attempting to use the Email sink (Serilog.Sinks.Email), but I can't figure out how to configure the network credentials property via an AppSetting.

    <add key="serilog:using" value="Serilog.Sinks.Email" />
    <add key="serilog:write-to:Email.mailServer" value="localhost" />
    <add key="serilog:write-to:Email.fromEmail" value="[email protected]" />
    <add key="serilog:write-to:Email.toEmail" value="[email protected]" />
    <add key="serilog:write-to:Email.restrictedToMinimumLevel " value="Error" />

<add key="serilog:write-to:Email.networkCredential" value="???" />

How can I specify/represent an NetworkCredential object using AppSettings? Is it even possible, or is this a limitation of the AppSetting approach to configuration in Serilog?

1
  • I had this working as you suggest with <add key="serilog:write-to:Email.credentials" value='{"Username":"[email protected]", "Password":"xxxxxx"}' /> but in my flailing I messed it up again. If I get it working once more, I will post the answer Oct 9, 2017 at 13:45

2 Answers 2

1

There isn't currently a nice way to do this, unfortunately.

Where this has popped up in the past we've sometimes added overloads with simple parameters - raising a bug or PR to that effect would be welcome.

Otherwise, reading the values out of AppSettings manually and configuring the sink in code is the best bet.

3
  • Is it still the case? Jun 29, 2015 at 1:47
  • 1
    Yes, though a PR adding a username/password overload would very likely be included. Cheers! Jun 30, 2015 at 4:36
  • Was this added yet? I would need this, too. Dec 15, 2016 at 13:39
0

Does Serilog pick up settings from the <mailSettings> element in your app.config? If not, this would make a good PR ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.