Open prandoz opened 2 months ago
Hi, I try to send mail with serilog, but I have this error:
Unable to find a method called Email for supplied arguments: batchingOptions, emailSubject, enableSsl, fromEmail, mailServer, outputTemplate, password, port, restrictedToMinimumLevel, toEmail, username. Candidate methods are: Email(from, to, host, port, connectionSecurity, credentials, subject, body, formatProvider, restrictedToMinimumLevel, levelSwitch) Email(options, batchingOptions, restrictedToMinimumLevel, levelSwitch)
My appsettings.json is: { "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" } }, "Serilog": { "Using": [ "Serilog.Sinks.Email" ], "MinimumLevel": { "Default": "Debug", "Override": { "Microsoft": "Warning" } }, "WriteTo": [ { "Name": "Email", "Args": { "fromEmail": "xx@gmail.com", "toEmail": [ "xy@gmail.com" ], "mailServer": "smtp.gmail.com", "port": 587, "enableSsl": true, "username": "xx@gmail.com", "password": "password", "emailSubject": "Mail Error", "restrictedToMinimumLevel": "Debug", "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] ({SourceContext}) {NewLine}{Message}{NewLine}{Exception}" } }, { "Name": "File", "Args": { "path": "Logs/Error_.log", "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] ({SourceContext}) {NewLine}{Message}{NewLine}{Exception}{NewLine}{NewLine}", "rollingInterval": "Day", "retainedFileCountLimit": 10, "restrictedToMinimumLevel": "Debug" } }, { "Name": "Console", "Args": { "restrictedToMinimumLevel": "Debug", "OutputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] {Message:lj}{NewLine}{Exception}" } } ] } }
and my Program.cs is:
`using Serilog;
var builder = WebApplication.CreateBuilder(args); Serilog.Debugging.SelfLog.Enable(Console.Out); Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(builder.Configuration) .CreateLogger();
builder.Host.UseSerilog(); builder.Services.AddControllers();
var app = builder.Build(); app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers();
app.Logger.LogDebug("Application started");
Log.Error("This is a test error to check email functionality");
app.Run();`
Thank you Andrea
Perahps this will help .Net Core and Serilog Email sink - JSON Config
Hi, I try to send mail with serilog, but I have this error:
Unable to find a method called Email for supplied arguments: batchingOptions, emailSubject, enableSsl, fromEmail, mailServer, outputTemplate, password, port, restrictedToMinimumLevel, toEmail, username. Candidate methods are: Email(from, to, host, port, connectionSecurity, credentials, subject, body, formatProvider, restrictedToMinimumLevel, levelSwitch) Email(options, batchingOptions, restrictedToMinimumLevel, levelSwitch)
My appsettings.json is: { "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" } }, "Serilog": { "Using": [ "Serilog.Sinks.Email" ], "MinimumLevel": { "Default": "Debug", "Override": { "Microsoft": "Warning" } }, "WriteTo": [ { "Name": "Email", "Args": { "fromEmail": "xx@gmail.com", "toEmail": [ "xy@gmail.com" ], "mailServer": "smtp.gmail.com", "port": 587, "enableSsl": true, "username": "xx@gmail.com", "password": "password", "emailSubject": "Mail Error", "restrictedToMinimumLevel": "Debug", "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] ({SourceContext}) {NewLine}{Message}{NewLine}{Exception}" } }, { "Name": "File", "Args": { "path": "Logs/Error_.log", "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] ({SourceContext}) {NewLine}{Message}{NewLine}{Exception}{NewLine}{NewLine}", "rollingInterval": "Day", "retainedFileCountLimit": 10, "restrictedToMinimumLevel": "Debug" } }, { "Name": "Console", "Args": { "restrictedToMinimumLevel": "Debug", "OutputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] {Message:lj}{NewLine}{Exception}" } } ] } }
and my Program.cs is:
`using Serilog;
var builder = WebApplication.CreateBuilder(args); Serilog.Debugging.SelfLog.Enable(Console.Out); Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(builder.Configuration) .CreateLogger();
builder.Host.UseSerilog(); builder.Services.AddControllers();
var app = builder.Build(); app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers();
app.Logger.LogDebug("Application started");
Log.Error("This is a test error to check email functionality");
app.Run();`
Thank you Andrea