serilog / serilog-settings-appsettings

An <appSettings> configuration reader for Serilog
Apache License 2.0
52 stars 23 forks source link

issue with NetworkCredentials #38

Open viettd1190 opened 5 years ago

viettd1190 commented 5 years ago

How to specify the networkCredential param using xml in Serilog.Sinks.Email. I try below but this cannot working

<add key="serilog:using:Email" value="Serilog.Sinks.Email"/>
    <add key="serilog:write-to:Email.connectionInfo:emailSubject" value="Test log from Serilog"/>
    <add key="serilog:write-to:Email.connectionInfo.fromEmail" value="xxxx@gmail.com"/>
    <add key="serilog:write-to:Email.connectionInfo:isBodyHtml" value="false"/>
    <add key="serilog:write-to:Email.connectionInfo.mailServer" value="smtp.gmail.com"/>
    <add key="serilog:write-to:Email.connectionInfo.networkCredentials.username" value="xxxx@gmail.com"/>
    <add key="serilog:write-to:Email.connectionInfo.networkCredentials.password" value="xxxxxxx"/>
    <add key="serilog:write-to:Email.connectionInfo.toEmail" value="xxxx@gmail.com"/>
    <add key="serilog:write-to:Email.connectionInfo.port" value="587"/>
    <add key="serilog:write-to:Email.outputTemplate" value="[{Timestamp:HH:mm:ss}];[{Level:u3}];{Message:lj}{NewLine}{Exception}"/>
    <add key="serilog:write-to:Email.restrictedToMinimumLevel" value="Debug"/>
Michael-Borges commented 5 years ago

I have the same problem. Do you found the answer?

tsimbalar commented 5 years ago

Long story short, you can't :-/

Serilog.Settings.AppSettings does not do "complex" object creation.

This Stack Overflow question offers a workaround. In the example, this is a workaround for the JSON settings, but you can do something similar, and then do this in your config :

<add key="serilog:write-to:EmailCustom.param1" value="Test log from Serilog"/>
<add key="serilog:write-to:EmailCustom.param2" value="Test log from Serilog"/>