使用Serilog登录到电子邮件接收器

时间:2019-03-09 05:07:46

标签: c# asp.net-core serilog

我有一个aspnet核心应用程序,我正在尝试配置serilog以向我发送电子邮件,但是没有运气。

我有此配置:

  Log.Logger = new LoggerConfiguration()
                 .MinimumLevel.Information()
                .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                .Enrich.FromLogContext()
                .WriteTo.File("1.log", LogEventLevel.Information, fileSizeLimitBytes: 10_000_000, rollOnFileSizeLimit: true, shared: true)
                .WriteTo.Email(new EmailConnectionInfo
                {
                    FromEmail = "xxx@gmail.com",
                    ToEmail = "yyy@gmail.com",
                    MailServer = "smtp.gmail.com",
                    NetworkCredentials = new NetworkCredential
                    {
                        UserName = "user",
                        Password = "pass"
                    },
                    EnableSsl = true,
                    Port = 587,
                    EmailSubject = "Error in app"
                }, restrictedToMinimumLevel: LogEventLevel.Error, batchPostingLimit: 1)
                .CreateLogger();

没有电子邮件。它写入文件,因此记录器处于活动状态。我想念什么吗?

0 个答案:

没有答案