Skip to content

krzysiek-b/serilog-sinks-email

 
 

Repository files navigation

Serilog.Sinks.Email

Build status

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"
                }
            }
        ]
    }

About

A Serilog sink that writes events to SMTP email

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 95.9%
  • PowerShell 2.9%
  • Shell 1.2%