Serilog.Sinks.Email 4.0.1-dev-00185

Serilog.Sinks.Email Build status

Sends log events by SMTP email.

ℹ️ Version 3.x of this package changes the name and structure of many configuration parameters from their 2.x names; see below for detailed information.

Package - Serilog.Sinks.Email

await using var log = new LoggerConfiguration()
    .WriteTo.Email(
        from: "app@example.com",
        to: "support@example.com",
        host: "smtp.example.com")
    .CreateLogger();

Supported options are:

Parameter Description
from The email address emails will be sent from.
to The email address emails will be sent to. Multiple addresses can be separated with commas or semicolons.
host The SMTP server to use.
port The port used for the SMTP connection. The default is 25.
connectionSecurity Choose the security applied to the SMTP connection. This enumeration type is supplied by MailKit. The default is Auto.
credentials The network credentials to use to authenticate with the mail server.
subject A message template describing the email subject. The default is "Log Messages".
body A message template describing the format of the email body. The default is "{Timestamp} [{Level}] {Message}{NewLine}{Exception}".
formatProvider Supplies culture-specific formatting information. The default is to use the current culture.

An overload accepting EmailSinkOptions can be used to specify advanced options such as batched and/or HTML body templates.

Sending batch email

To send batch email, supply WriteTo.Email with a batch size:

await using var log = new LoggerConfiguration()
    .WriteTo.Email(
        options: new()
        {
            From = "app@example.com",
            To = "support@example.com",
            Host = "smtp.example.com",
        },
        batchingOptions: new()
        {
            BatchSizeLimit = 10,
            BufferingTimeLimit = TimeSpan.FromSeconds(30),
        })
    .CreateLogger();

Batch formatting can be customized using options.Body.

Sending HTML email

To send HTML email, specify a custom IBatchTextFormatter in options.Body and set options.IsBodyHtml to true:

await using var log = new LoggerConfiguration()
    .WriteTo.Email(
        options: new()
        {
            From = "app@example.com",
            To = "support@example.com",
            Host = "smtp.example.com",
            Body = new MyHtmlBodyFormatter(),
            IsBodyHtml = true,
        },
        batchingOptions: new()
        {
            BatchSizeLimit = 10,
            BufferingTimeLimit = TimeSpan.FromSeconds(30),
        })
    .CreateLogger();

A simplistic HTML formatter is shown below:

class MyHtmlBodyFormatter : IBatchTextFormatter
{
    public void FormatBatch(IEnumerable<LogEvent> logEvents, TextWriter output)
    {
        output.Write("<table>");
        foreach (var logEvent in logEvents)
        {
            output.Write("<tr>");
            Format(logEvent, output);
            output.Write("</tr>");
        }

        output.Write("</table>");
    }

    public void Format(LogEvent logEvent, TextWriter output)
    {
        using var buffer = new StringWriter();
        logEvent.RenderMessage(buffer);
        output.Write(WebUtility.HtmlEncode(buffer.ToString()));
    }
}

No packages depend on Serilog.Sinks.Email.

.NET Framework 4.6.2

.NET Framework 4.7.1

.NET 6.0

.NET 8.0

.NET Standard 2.0

Version Downloads Last updated
4.1.0 12 04/24/2025
4.1.0-dev-02303 11 04/25/2025
4.1.0-dev-02301 11 04/25/2025
4.0.1-dev-00185 11 04/24/2025
4.0.0 19 06/17/2024
4.0.0-dev-00177 19 06/17/2024
3.0.0 38 03/09/2024
3.0.0-dev-00174 14 06/17/2024
3.0.0-dev-00171 18 06/17/2024
3.0.0-dev-00166 22 02/08/2024
3.0.0-dev-00161 30 02/13/2024
2.4.1-dev-00147 19 02/13/2024
2.4.1-dev-00135 20 02/13/2024
2.4.1-dev-00128 18 02/13/2024
2.4.0 22 09/08/2021
2.4.0-dev-00116 19 02/13/2024
2.3.1-dev-00101 19 02/13/2024
2.3.1-dev-00100 20 02/13/2024
2.3.1-dev-00092 21 02/13/2024
2.3.0 23 02/08/2024
2.2.2-dev-00070 18 02/13/2024
2.2.1-dev-00067 33 02/13/2024
2.2.0 32 02/08/2024
2.2.0-dev-00057 19 02/13/2024
2.1.1-dev-00056 20 02/13/2024
2.1.0 24 02/08/2024
2.1.0-dev-00048 21 02/13/2024
2.1.0-dev-00046 20 02/13/2024
2.0.0 21 02/08/2024
1.5.37 19 02/08/2024
1.5.34 22 02/08/2024
1.5.25 22 02/08/2024
1.5.23 21 02/08/2024
1.5.20 20 02/08/2024
1.5.15 20 02/08/2024
1.5.13 20 02/08/2024
1.5.11 22 02/08/2024
1.5.10 20 02/08/2024
1.5.9 21 02/08/2024
1.5.8 25 02/08/2024
1.5.5 21 02/08/2024
1.5.3 24 02/08/2024
1.4.196 21 02/08/2024
1.4.182 21 02/08/2024
1.4.168 22 02/08/2024
1.4.155 22 02/08/2024
1.4.139 32 02/08/2024
1.4.118 28 02/08/2024
1.4.113 25 02/08/2024
1.4.102 23 02/08/2024
1.4.99 24 02/08/2024
1.4.97 21 02/08/2024
1.4.76 22 02/08/2024
1.4.39 23 02/08/2024
1.4.34 23 02/08/2024
1.4.28 28 02/08/2024
1.4.27 19 02/08/2024
1.4.23 21 02/08/2024
1.4.22 20 02/08/2024
1.4.21 22 02/08/2024
1.4.18 20 02/08/2024
1.4.15 0 11/04/2014
1.4.14 0 10/23/2014
1.4.13 0 10/23/2014
1.4.12 0 10/12/2014
1.4.11 0 10/08/2014
1.4.10 0 09/26/2014
1.4.9 0 09/17/2014
1.4.8 0 09/11/2014
1.4.7 0 09/01/2014
1.4.6 0 08/31/2014
1.4.5 0 08/27/2014
1.4.4 0 08/27/2014
1.4.3 0 08/25/2014
1.4.2 0 08/23/2014
1.4.1 0 08/23/2014
1.3.43 0 08/04/2014
1.3.42 0 07/30/2014
1.3.41 0 07/28/2014
1.3.40 0 07/26/2014
1.3.39 0 07/25/2014
1.3.37 0 07/25/2014
1.3.36 0 07/20/2014
1.3.35 0 07/17/2014
1.3.34 0 07/06/2014
1.3.33 0 06/30/2014
1.3.30 0 06/19/2014
1.3.29 0 06/19/2014
1.3.28 0 06/19/2014
1.3.27 0 06/18/2014
1.3.26 0 06/18/2014
1.3.25 0 06/09/2014
1.3.24 0 05/21/2014
1.3.23 0 05/20/2014
1.3.20 0 05/18/2014
1.3.19 0 05/17/2014
1.3.18 0 05/17/2014
1.3.17 0 05/17/2014
1.3.16 0 05/17/2014
1.3.15 0 05/16/2014
1.3.14 0 05/16/2014
1.3.13 0 05/16/2014
1.3.12 0 05/14/2014
1.3.7 0 05/11/2014
1.3.6 0 05/09/2014
1.3.5 0 05/06/2014
1.3.4 0 05/04/2014
1.3.3 0 04/28/2014
1.3.1 0 04/26/2014
1.2.53 0 04/26/2014
1.2.52 0 04/24/2014
1.2.51 0 04/18/2014
1.2.50 0 04/18/2014
1.2.49 0 04/17/2014
1.2.48 0 04/14/2014
1.2.47 0 04/14/2014
1.2.45 0 04/13/2014
1.2.44 0 04/09/2014
1.2.41 0 04/07/2014
1.2.40 0 04/07/2014
1.2.39 0 03/29/2014
1.2.37 0 03/29/2014
1.2.29 0 03/16/2014
1.2.27 0 03/14/2014
1.2.26 0 03/12/2014
1.2.25 0 02/20/2014
0.9.9 0 11/23/2013
0.9.8 0 11/01/2013