I am trying to use Serilog's Email sink as part of simple console application. This application has very short lifetime: it checks DB and updates subscribers with a new data. I want to send an email if error happens.
The problem is that if I don't put Thread.Sleep at the end of the app, emails are not sent.
Is there any way to purge email queue and force email to be sent asap?
My code is:
Log.Logger = new LoggerConfiguration()
.WriteTo.ColoredConsole()
.WriteTo.EventLog("LOGSOURCE", restrictedToMinimumLevel: LogEventLevel.Warning)
.WriteTo.Email(connectionInfo: new EmailConnectionInfo()
{
EmailSubject = "App error",
ToEmail = "support@company.com",
MailServer = "smtp.office365.com",
NetworkCredentials = new NetworkCredential("sender@company.com", "Password"),
Port = 587,
FromEmail = "sender@company.com",
EnableSsl = false
},
batchPostingLimit: 1,
restrictedToMinimumLevel: LogEventLevel.Error)
.CreateLogger();
Log.Error("Error message");
Any help is appreciated