6

I have an aspnet core app and I'm trying to configure serilog to send me emails, with no luck.

I have this configuration:

  Log.Logger = new LoggerConfiguration()
                 .MinimumLevel.Information()
                .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                .Enrich.FromLogContext()
                .WriteTo.File("1.log", LogEventLevel.Information, fileSizeLimitBytes: 10_000_000, rollOnFileSizeLimit: true, shared: true)
                .WriteTo.Email(new EmailConnectionInfo
                {
                    FromEmail = "xxx@gmail.com",
                    ToEmail = "yyy@gmail.com",
                    MailServer = "smtp.gmail.com",
                    NetworkCredentials = new NetworkCredential
                    {
                        UserName = "user",
                        Password = "pass"
                    },
                    EnableSsl = true,
                    Port = 587,
                    EmailSubject = "Error in app"
                }, restrictedToMinimumLevel: LogEventLevel.Error, batchPostingLimit: 1)
                .CreateLogger();

No emails. It writes to the file, so the logger is active. Anything I'm missing?

ArunPratap
  • 4,816
  • 7
  • 25
  • 43
Evgeni
  • 3,341
  • 7
  • 37
  • 64

1 Answers1

-1
 {
        FromEmail = "xxx@gmail.com",
        ToEmail = "yyy@gmail.com",
        MailServer = "smtp.gmail.com",
        NetworkCredentials = new NetworkCredential
        {
            UserName = "xxx@gmail.com",
            Password = "zzz"
        },
        EnableSsl = true,
        Port = 465,
        EmailSubject = "Error in app"
    }

This work for me.

ccassob
  • 335
  • 3
  • 10