https://github.com/ttakahari/log2slack
Extensions that sends logs to Slack with loggers.
https://github.com/ttakahari/log2slack
csharp log logger logging slack
Last synced: 8 months ago
JSON representation
Extensions that sends logs to Slack with loggers.
- Host: GitHub
- URL: https://github.com/ttakahari/log2slack
- Owner: ttakahari
- License: mit
- Created: 2018-08-18T08:27:58.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-03-11T10:30:14.000Z (over 7 years ago)
- Last Synced: 2025-09-14T16:57:27.287Z (9 months ago)
- Topics: csharp, log, logger, logging, slack
- Language: C#
- Homepage:
- Size: 16.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Log2Slack
Extensions that sends logs to slack with loggers.
Supported loggers are [NLog](http://nlog-project.org/) and [log4net](https://logging.apache.org/log4net/).
[](https://ci.appveyor.com/project/ttakahari/Log2Slack)
[](https://www.nuget.org/packages/Log2Slack.NLog/)
[](https://www.nuget.org/packages/Log2Slack.Log4Net/)
## Install
from NuGet - [Log2Slack.NLog](https://www.nuget.org/packages/Log2Slack.NLog/)
from NuGet - [Log2Slack.Log4Net](https://www.nuget.org/packages/Log2Slack.Log4Net/)
```ps1
PM > Install-Package Log2Slack.NLog
PM > Install-Package Log2Slack.Log4Net
```
## How to use
### NLog
If you use a XML file, configure as follow.
```xml
```
If you write codes instead of a XML file, configure as follow.
```csharp
// create an instance of NLog.Config.LoggingConfiguration.
var configuration = new LoggingConfiguration();
// create an instance of Log2Slack.NLog.SlackTarget.
var target = new SlackTarget
{
WebHookUrl = "https://hooks.slack.com/services/xxx", // your Incoming-WebHook URL.
SerializerType = typeof(SlackSharp.Serialization.Jil.JilSerializer), // type of a serializer impletemting SlackSharp.IHttpContentJsonSerializer.
Layout = "${message}" // log content layout
};
// add the target with a name.
configuration.AddTarget("slack", target);
// according to the rules of NLog.
```
### log4net
If you use a XML file, configure as follow.
```xml
```
If you write codes instead of a XML file, configure as follow.
```csharp
// create an instance of log4net.Layout.PatternLayout and call ActivateOptions method.
var layout = new PatternLayout
{
ConversionPattern = "%message",
};
layout.ActivateOptions();
// create an instance of Log2Slack.Log4Net.SlackAppender and call ActivateOptions method.
var appender = new SlackAppender
{
WebHookUrl = "https://hooks.slack.com/services/xxx", // your Incoming-WebHook URL.
SerializerType = typeof(SlackSharp.Serialization.Jil.JilSerializer), // type of a serializer impletemting SlackSharp.IHttpContentJsonSerializer.
Layout = layout // log content layout
};
appender.ActivateOptions();
// create an instance of log4nt.Repository.Hierarchy.Hierarchy and add the appender.
var repository = (Hierarchy)LogManager.CreateRepository(GetType().Assembly, typeof(Hierarchy));
repository.Root.AddAppender(appender);
// according to the rules of log4net.
```
## Lisence
under [MIT Lisence](https://opensource.org/licenses/MIT).