serilog / serilog-sinks-email

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

Able to build the .net core project with serilog email sink but not receiving the emails on error. #92

Closed satyaram243 closed 6 months ago

satyaram243 commented 3 years ago

I am currently working on a .Net core 3 project. I have files and email sink setup for logging in the errors. I am able to see the errors logging in file but not getting emails. When I add a debug statement inside the custom email method, I am able to see all the app setting. I am using the following code and app settings for email sink.

{ "Name": "CustomEmail", "Args": { "ConnectionInfo": { "NetworkCredentials": { "UserName": null, "Password": null }, "FromEmail": "test@test.com", "MailServer": "test", "EmailSubject": "[{Level}] <{MachineName}> Log Email", "Port": "25", "IsBodyHtml": false, "EnableSsl": false, "ToEmail": "test@test.com" }, "RestrictedToMinimumLevel": "Error", "OutputTemplate": "{Timestamp:yyyy-MM-dd HH:mm} [{Level}] <{MachineName}> {Message}{NewLine}{Exception}" } } image image

nCubed commented 2 years ago

Not entirely sure why your extensions is failing, but the first thing is to move the configuration of the Serilog self logger to before the logger is created:

public static void Main(string[] args)
{
    SelfLog.Enable(msg => Debug.WriteLine(msg));
    // add remainder of code ....
}

By enabling the self log before the logger is created, you'll be able to see any configuration errors that may be occurring during the LoggerConfiguration lifecycle.

p.s. please don't post images of code.

xantari commented 1 year ago

@satyaram243 What were the results of the self log?

nblumhardt commented 6 months ago

Hi! Thanks for your message. This one would be a good fit for the serilog tag on Stack Overflow (only minimal maintainer time available here). Closing as stale, sorry about the lack of response earlier on.