Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Stherm 15 posts 85 karma points
    Dec 06, 2019 @ 20:31
    Stherm
    0

    How to setup seriLog.sinks.email with network credential

    Hi, I'm trying to set up Serilog to send email + file logging. I use mailjet as my email server and I'm not able to set it up correctly with networkcredentials. Here is my config (with personnal data removed).

    <add key="serverUrl" value="localhost"/>
    <add key="serilog:using:Email" value="Serilog.Sinks.Email" />
    <add key="serilog:write-to:Email.fromEmail" value="emailfrom"/>
    <add key="serilog:write-to:Email.toEmail" value="emailto" />
    <add key="serilog:write-to:Email.mailServer" value="in-v3.mailjet.com" />
    
    <add key="serilog:enrich:with-property:environment" value="Localhost" />
    <add key="serilog:write-to:Email.port" value="587"/>
    <add key="serilog:write-to:Email.networkCredentials" value="'username':'username' 'password':'password'"/>
    
    <add key="serilog:write-to:Email.EnableSsl" value="true"/>
    <add key="serilog:write-to:Email.mailSubject" value="[{environment} - {MachineName}]" />
    <add key="serilog:write-to:Email.outputTemplate" value="{Timestamp:yyyy-MM-dd  HH:mm:ss}:: [{SourceContext} {NewLine}{Level:u3} - {Message:lj}{NewLine}{Exception}{SourceContext}]" />
    <add key="serilog:write-to:Email.restrictedToMinimumLevel" value="Error" />
    

    I don,t knw what I'm doing wrong with this. If i use another smtp (Email.mailServer) that doesn't need credentials, it works, but i can't use this one in production.

  • Alex 22 posts 105 karma points
    Jun 02, 2020 @ 04:21
    Alex
    0

    hi, did you find how to provide credentials for Email logging? I have the same issue.

  • Frans de Jong 522 posts 1762 karma points c-trib
    Jul 02, 2020 @ 15:26
    Frans de Jong
    0

    I'm just trying the same and no luck...

  • Frans de Jong 522 posts 1762 karma points c-trib
    Feb 01, 2021 @ 10:10
    Frans de Jong
    0

    For future reference:

    I've used the Nlog sink and setup the emails in there.

    We used the following config settings: Serilog.user.config:

      <add key="serilog:using:NLog" value="Serilog.Sinks.NLog" />
        <add key="serilog:write-to:NLog.restrictedToMinimumLevel" value="Error" />
        <add key="serilog:write-to:NLog.outputTemplate" value="{Message:lj}{NewLine}{Timestamp:yyyy-MM-dd HH:mm:ss,fff} [P{ProcessId}/D{AppDomainId}/T{ThreadId}] {Log4NetLevel} {SourceContext}{NewLine}{Exception}" />
    

    Web.config: We use a appsetting to check on what environment the error is thrown <add key="Environment" value="Environment" />

     <nlog>
    <targets>
      <target name="errormail" type="Mail" layout="${exception} on ${appsetting:Environment} - ${message} " subject="Error on Site name ${appsetting:Environment} environment" to="[email protected]" useSystemNetMailSettings="true" />
    </targets>
    <rules>
      <logger name="*" minlevel="Info" writeTo="errormail" />
    </rules>
    

    Register the nlog config in configsections:

        <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
    

    Hope this will help anyone.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies