A batching Serilog sink for Slack, narochno. Each log message is sent as an attachment on the same message, with the log event properties rendered out as fields.
var webHookUrl = "your webhook URL";
var services = new ServiceCollection();
services.AddSlack(new SlackConfig()
{
WebHookUrl = webHookUrl
});
var serviceProvider = services.BuildServiceProvider();
var slackClient = serviceProvider.GetRequiredService<ISlackClient>();
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.SlackBlocking(slackClient, LogEventLevel.Information)
.CreateLogger();
Log.Information("Testing!");
More on correct usage of DI and Serilog on ASP.NET Core
can be found here.
https://nblumhardt.com/2020/09/serilog-inject-dependencies/
See the Narochno.Slack project for more information.