serilog / serilog-sinks-email

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

Serilog-sinks is not sending email in docker container when error occurs #52

Closed liaoqixiang closed 9 months ago

liaoqixiang commented 6 years ago

Log.Logger = new LoggerConfiguration() .WriteTo.Console(restrictedToMinimumLevel: LogEventLevel.Verbose) .WriteTo.Email(new EmailConnectionInfo() { FromEmail = configuration["Email:fromEmail"], EmailSubject = configuration["Email:subjectEmail"], ToEmail = configuration["Email:toEmail"], MailServer = configuration["Email:mailServer"], }, restrictedToMinimumLevel: LogEventLevel.Error) .CreateLogger();

This is my setting. It can send email in local environment but not in docker container. Could anyone have a look to see what is going on?

merbla commented 6 years ago

@liaoqixiang initial thoughts relate to network communication being an issue. How are you addressing your email server (e.g. IP vs DNS)? What ports have you exposed?

liaoqixiang commented 6 years ago

@merbla Hi there, your thought is I haven't set up the port correctly? there is no setting about port in my docker compose file. I guess it is port 80? my email server is smtp server

merbla commented 6 years ago

Are you resolving the email server via DNS?

liaoqixiang commented 6 years ago

@merbla I think it's IP? It is in my company.

liaoqixiang commented 6 years ago

@merbla I think I need to check the port tomorrow. Thanks

liaoqixiang commented 6 years ago

@merbla I have tried different ports. It seems it's still not working. This web API is using port 80.

merbla commented 6 years ago

@liaoqixiang can you try logging to the Serilog console and also use SelfLog to expose any errors that might be occurring.

e.g. https://github.com/serilog/serilog/wiki/Debugging-and-Diagnostics#selflog

merbla commented 6 years ago

@liaoqixiang if you can post an example of the issue that might help working out the details. My assumption is that it will relate to configuration in Docker.

liaoqixiang commented 6 years ago

@merbla

Here are all the settings.

Docker file:

FROM microsoft/aspnetcore:2.0.6 ARG source WORKDIR /app EXPOSE 80 COPY ${source:-obj/Docker/publish} . ENV TZ=NZ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ /etc/timezone ENTRYPOINT ["dotnet", "PPPECSInterface.dll"]

Dokcer-compose file: version: '3.4'

services: pppecsinterface: image: pppecsinterface build: context: ./ECS dockerfile: Dockerfile

Docker-compose-override: version: '3.4'

services: pppecsinterface: environment:

Program.cs public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args)

// .UseKestrel() // .UseIISIntegration() .UseStartup() // .UseUrls("http://0.0.0.0:80") .UseDefaultServiceProvider(options => options.ValidateScopes = false) .Build();

liaoqixiang commented 6 years ago

@merbla I don't see there is a problem of port. It's totally ok if I send email from docker using smtpclient class provided in .net.

nblumhardt commented 9 months ago

Closing this one as stale, hope you were able to find a resolution.