Serilog Email Sink to use for sending email via Office 365

时间:2015-05-12 23:17:44

标签: email serilog

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:

 database.GET({
   model: someModel,
   sort: 'something',
   limit: {},
   options: {}
 }).then(function (result) {
   res.json(result);
 }).then(undefined, function (error) {
   console.log('Error: ' + error);
 });

Any help is appreciated

3 个答案:

答案 0 :(得分:1)

您可以尝试使用Serilog.Debugging.SelfLog.Out = Console.Out

调试Serilog

我认为您应该使用带有o365的EnableSsl = true并将batchPostingLimit保留为默认值= 100

答案 1 :(得分:0)

根据接收器(我不确定电子邮件),处理记录器可能会产生正确的效果:

((IDisposable)Log.Logger).Dispose();

如果不这样做,可能需要在电子邮件接收器中进行额外的工作以确保正确刷新内容(在Serilog跟踪器上提高票证会对此有所帮助)。

答案 2 :(得分:0)

您是否尝试过以下操作?

Log.CloseAndFlush();