Sends log events by SMTP email.
Package - Serilog.Sinks.Email | Platforms - .NET 4.5
var log = new LoggerConfiguration()
.WriteTo.Email(
fromEmail: "[email protected]",
toEmail: "[email protected]",
mailServer: "smtp.example.com")
.CreateLogger();
An overload accepting EmailConnectionInfo
can be used to specify advanced options.
Other types of email transport can be also used like SqlServer sp_send_dbmail
var log = new LoggerConfiguration()
.WriteTo.Email(ńew SqlServerEmailConnectionInfo
{
ToEmail = "[email protected]",
MailProfileName = "My_Profile",
SqlConnectionString = "Data Source=(local);..."
})
.CreateLogger();
You can also use appsettings.json when Serilog.Configuration is used combined with filters to send only exceptions eg. on environments where monitoring is limited.
"Serilog": {
"Using": [ "Serilog" ],
"MinimumLevel": "Error",
"WriteTo": [
{
"Name": "Email",
"Args": {
"sqlConnectionString": "Data Source=(local);...",
"mailProfileName": "My_Profile",
"toEmail": "[email protected]",
"mailSubject": "Exception on PROD"
}
}
]
}