A Serilog sink that writes events as messages to Slack. Slack client was developed in F#.
Package - Serilog.Sinks.SlackClient | Platforms - .NET 4.5.1
.NET Core now supported - Just download this package (only incoming webhooks are supported in this package)
You'll need to have a Channel Id and a Token on your Slack team to be able to send messages. To manage tokens go to Slack Tokens. In the example shown, the Channel Id in use is XXXXXXXXX
and the token is yyyyyyyyyyyy
.
var log = new LoggerConfiguration()
.WriteTo.Slack("XXXXXXXXX", "yyyyyyyyyyyy", LevelAlias.Maximum)
.CreateLogger();
log.Fatal("This is an fatal message!");
Example:
Other option is to use incoming webhooks:
var log = new LoggerConfiguration()
.WriteTo.Slack("https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX")
.CreateLogger();
log.Fatal("This is an fatal message!");
Example:
To change the default renderization pass a delegate as an additional parameter:
var log = new LoggerConfiguration()
.WriteTo.Slack("https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
(LogEvent l) => l.RenderMessage())
.CreateLogger();
For more information about the default render function take a look to:
string RenderMessage(LogEvent logEvent)
at SlackSink.cs