Sink sends email with only the first message
akordowski opened this issue · 2 comments
akordowski commented
In a .Net Core 3.1 console application the email sink sends a email which contains only the first message. All other following messages are not sent. Am I missing something in the configuration?
Code
class Program
{
static void Main(string[] args)
{
var emailConnectionInfo = new EmailConnectionInfo
{
FromEmail = "FromEmail",
ToEmail = "ToEmail",
EmailSubject = "EmailSubject",
MailServer = "MailServer",
Port = 123,
NetworkCredentials = new NetworkCredential("username", "password")
};
var logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.Console()
.WriteTo.Email(emailConnectionInfo, batchPostingLimit: 250)
.CreateLogger();
logger.Verbose("Verbose Message");
logger.Debug("Debug Message");
logger.Information("Information Message");
logger.Warning("Warning Message");
logger.Error("Error Message");
logger.Fatal("Fatal Message");
}
}
Received email
2020-08-30 23:00:00.000 [Verbose] Verbose Message
akordowski commented
I tested the code using the latest 2.4.0-dev-00116
package version. With this version it sends no email at all.
akordowski commented
I got it work with the latest 2.4.0-dev-00116
package and the following code.
Increase the period to send
a email only at the end of the execution.
static void Main(string[] args)
{
var emailConnectionInfo = new EmailConnectionInfo
{
FromEmail = "FromEmail",
ToEmail = "ToEmail",
EmailSubject = "EmailSubject",
MailServer = "MailServer",
Port = 123,
NetworkCredentials = new NetworkCredential("username", "password")
};
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.Console()
.WriteTo.Email(emailConnectionInfo, period: TimeSpan.FromSeconds(300))
.CreateLogger();
var logger = Log.Logger;
logger.Verbose("Verbose Message");
logger.Debug("Debug Message");
logger.Information("Information Message");
logger.Warning("Warning Message");
logger.Error("Error Message");
logger.Fatal("Fatal Message");
Log.CloseAndFlush();
}