mattosaurus / Serilog.Sinks.SendGridEmail

Sends the email notification through SendGrid

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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();

About

Sends the email notification through SendGrid

License:MIT License


Languages

Language:C# 100.0%