serilog / serilog-sinks-email

A Serilog sink that writes events to SMTP email
Apache License 2.0
70 stars 68 forks source link

batch posting limit is not working when other sink is attached #66

Closed danielklecha closed 6 months ago

danielklecha commented 5 years ago

Hi, I created console application with attached code and used smtp4dev as server. App should send single email but when console sink is attached then I get two emails - with 2 logs and with next 4 logs. When I comment console sink then I get single email. What is wrong? Is it a bug?

Serilog.Debugging.SelfLog.Enable(Console.WriteLine);
var emailConnectionInfo = new EmailConnectionInfo
{
    FromEmail = "from@test.com",
    EnableSsl = false,
    EmailSubject = "subject",
    IsBodyHtml = false,
    MailServer = "localhost",
    ToEmail = "to@test.com",
    NetworkCredentials = null,
    Port = 25
};
using (var logger = new LoggerConfiguration()
    .Enrich.FromLogContext()
    .WriteTo.Console()
    .WriteTo.Email(emailConnectionInfo, batchPostingLimit: 500, restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Warning)
    .CreateLogger())
{
    logger.Information("message");
    logger.Information("message");
    logger.Warning("message");
    logger.Error("message");
    logger.Information("message");
    logger.Information("message");
    logger.Warning("message");
    logger.Error("message");
    logger.Warning("message");
    logger.Warning("message");
}
ghost commented 4 years ago

+1

ktodyruik commented 4 years ago

I'm having a similar issue with periodic batching. I'm running some code on an hourly schedule. Error and warning messages should batch and be sent out as one email. It was working at first, batching up the messages in one email, and now it is sending out two emails -- one with each event, even though the events are < 30 seconds apart. When I changed the period to 5 minutes, it sends out two emails 5 minutes apart with log events that occurred seconds apart.

nblumhardt commented 6 months ago

Closing this one as stale; I think the batching functionality in this sink is too rudimentary to provide this level of control, currently. Cheers!