Harmonickey / Serilog.Sinks.SendGridEmail

Sends the email notification through SendGrid
MIT License
2 stars 3 forks source link

Serilog SendGrid Email Sink

Download the SendGrid NuGet Package and the SendGridEmail NuGet Package

Install-Package Serilog.Sinks.SendGridEmail

Create an Instance of the SendGridClient (SendGrid namespace)

var client = new SendGridClient("Your Send Grid API Key");

Create an EmailConnectionInfo (Serilog.Sinks.Email namespace)

var emailConnectionInfo = new EmailConnectionInfo
{
    EmailSubject = "Application Error",
    FromEmail = "Your From Email",
    ToEmail = "Your To Email",
    SendGridClient = client,
    FromName = "Your Friendly From Name"
};

Create your own customized Serilog logger, and then include the .WriteTo.Email extension, just like with the Serilog.Sinks.Email NuGet package.

Log.Logger = new LoggerConfiguration()
    .MinimumLevel.Is(LogEventLevel.Debug)
    .Enrich.WithProcessId()
    .Enrich.WithThreadId()
    .WriteTo.Email(emailConnectionInfo, restrictedToMinimumLevel: LogEventLevel.Error)
    .CreateLogger();