Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't load email Setting #141

Open
prandoz opened this issue Sep 27, 2024 · 1 comment
Open

Can't load email Setting #141

prandoz opened this issue Sep 27, 2024 · 1 comment

Comments

@prandoz
Copy link

prandoz commented Sep 27, 2024

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": "[email protected]",
"toEmail": [ "[email protected]" ],
"mailServer": "smtp.gmail.com",
"port": 587,
"enableSsl": true,
"username": "[email protected]",
"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

@alwilton
Copy link

Perahps this will help
.Net Core and Serilog Email sink - JSON Config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants