serilog-settings-appsettings icon indicating copy to clipboard operation
serilog-settings-appsettings copied to clipboard

issue with NetworkCredentials

Open viettd1190 opened this issue 5 years ago • 2 comments

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="[email protected]"/>
    <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="[email protected]"/>
    <add key="serilog:write-to:Email.connectionInfo.networkCredentials.password" value="xxxxxxx"/>
    <add key="serilog:write-to:Email.connectionInfo.toEmail" value="[email protected]"/>
    <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"/>

viettd1190 avatar Jun 13 '19 04:06 viettd1190

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

Michael-Borges avatar Jun 27 '19 21:06 Michael-Borges

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"/>

tsimbalar avatar Jun 28 '19 07:06 tsimbalar