Skip to content

serilog-contrib/serilog-sinks-slackclient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serilog.Sinks.Slack

Contributors needed!


Build status NuGet Version NuGet Version

A Serilog sink that writes events as messages to Slack. Slack client was developed in F#.

Package - Serilog.Sinks.SlackClient | Platform - .NET 4.5.1

Package - Serilog.Sinks.Slack.Core | Platform - .NET Standard 2.0.1

.NET Core now supported - Just download this package NuGet Version (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:

Simple Message

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:

Simple Message

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