Noise.Notice.Core
1.0.0
dotnet add package Noise.Notice.Core --version 1.0.0
NuGet\Install-Package Noise.Notice.Core -Version 1.0.0
<PackageReference Include="Noise.Notice.Core" Version="1.0.0" />
paket add Noise.Notice.Core --version 1.0.0
#r "nuget: Noise.Notice.Core, 1.0.0"
// Install Noise.Notice.Core as a Cake Addin #addin nuget:?package=Noise.Notice.Core&version=1.0.0 // Install Noise.Notice.Core as a Cake Tool #tool nuget:?package=Noise.Notice.Core&version=1.0.0
<p align="center"> <a href="https://github.com/Bryan-Cyf/NoiseNotice" target="_blank" rel="noopener noreferrer"> <img width="100" src="https://github.com/Bryan-Cyf/NoiseNotice/blob/master/media/nuget-icon.png" alt="NoiseNotice logo" /> </a> </p>
<p align="center"><b>NoiseNotice</b>强大易用的消息通知组件 </p>
<p align="center"> <a href="https://www.nuget.org/packages/NoiseNotice.Core"><img alt="nuget release" src="https://img.shields.io/nuget/v/NoiseNotice.Core" /></a> <a href="https://www.nuget.org/packages/NoiseNotice.Core"><img alt="nuget release" src="https://img.shields.io/nuget/dt/NoiseNotice.Core" /></a> <br /> <a href="https://chenyuefeng.blog.csdn.net/article/details/129963124">文档</a> </p>
NoiseNotice
这是一个基于.NET开源的消息通知组件,它包含了邮件通知、钉钉、飞书、企业微信通知,可以帮助我们更容易地发送程序异常通知!
Nuget包
Package Name | Version | Downloads |
---|---|---|
NoiseNotice.Core | ||
NoiseNotice.Dingtalk | ||
NoiseNotice.Email | ||
NoiseNotice.Feishu | ||
NoiseNotice.Weixin |
功能介绍
- 支持[邮件]、[钉钉]、[飞书]、[企业微信]方式发送
- 支持@指定人员
- 支持自定义发送间隔,避免同样的异常频繁通知
- 傻瓜式配置,开箱即用
平台支持
- SMTP邮箱
- 钉钉群机器人
- 飞书群机器人
- 企业微信群机器人
文档资料
项目接入
项目接入提供了以下发送方式的Demo:邮件通知、钉钉通知、飞书、企业微信通知
1. 邮件通知
邮件通知支持同时发送给多个收件人
Step 1 : 安装包,通过Nuget安装包
Install-Package NoiseNotice.Core
Install-Package NoiseNotice.Email
Step 2 : 配置 Startup 启动类
public class Startup
{
//...
public void ConfigureServices(IServiceCollection services)
{
//configuration
services.AddNoiseNotice(config =>
{
config.IntervalSeconds = 10;//同一标题的消息,10秒内只能发一条,避免短时间内大量发送重复消息
config.UseEmail(option =>
{
option.Host = "smtp.qq.com";//SMTP地址
option.Port = 465;//SMTP端口
option.FromName = "System";//发送人名字(自定义)
option.FromAddress = "12345@qq.com";//发送邮箱
option.Password = "passaword";//秘钥
option.ToAddress = new List<string>()//收件人集合
{
"12345@qq.com"
};
});
});
}
}
Step 3 : IEmailProvider服务接口使用
[ApiController]
[Route("[controller]/[action]")]
public class NoticeController : ControllerBase
{
private readonly IEmailProvider _mailProvider;
public NoticeController(IEmailProvider provider)
{
_mailProvider = provider;
}
[HttpGet]
public async Task SendMail([FromQuery] string str)
{
await _mailProvider.SendAsync(str, new Exception(str));
}
}
2. 钉钉通知
Step 1 : 安装包,通过Nuget安装包
Install-Package NoiseNotice.Core
Install-Package NoiseNotice.Dingtalk
Step 2 : 配置 Startup 启动类
public class Startup
{
//...
public void ConfigureServices(IServiceCollection services)
{
//configuration
services.AddNoiseNotice(config =>
{
config.IntervalSeconds = 10;//同一标题的消息,10秒内只能发一条,避免短时间内大量发送重复消息
config.UseDingTalk(option =>
{
option.WebHook = "https://oapi.dingtalk.com/robot/send?access_token=xxxxx";//通知地址
option.Secret = "secret";//签名校验
});
});
}
}
Step 3 : IDingtalkProvider服务接口使用
[ApiController]
[Route("[controller]/[action]")]
public class NoticeController : ControllerBase
{
private readonly IDingtalkProvider _dingtalkProvider;
public NoticeController(IDingtalkProvider dingtalkProvider)
{
_dingtalkProvider = dingtalkProvider;
}
[HttpGet]
public async Task SendDingTalk([FromQuery] string str)
{
await _dingtalkProvider.SendAsync(str, new Exception(str));
}
}
3. 飞书通知
Step 1 : 安装包,通过Nuget安装包
Install-Package NoiseNotice.Core
Install-Package NoiseNotice.Feishu
Step 2 : 配置 Startup 启动类
public class Startup
{
//...
public void ConfigureServices(IServiceCollection services)
{
//configuration
services.AddNoiseNotice(config =>
{
config.IntervalSeconds = 10;//同一标题的消息,10秒内只能发一条,避免短时间内大量发送重复消息
config.UseFeishu(option =>
{
option.WebHook = "https://open.feishu.cn/open-apis/bot/v2/hook/xxxxx";//通知地址
option.Secret = "secret";//签名校验
});
});
}
}
Step 3 : IFeishuProvider服务接口使用
[ApiController]
[Route("[controller]/[action]")]
public class NoticeController : ControllerBase
{
private readonly IFeishuProvider _feishuProvider;
public NoticeController(IFeishuProvider feishuProvider)
{
_feishuProvider = feishuProvider;
}
[HttpGet]
public async Task SendFeishu([FromQuery] string str)
{
await _feishuProvider.SendAsync(str, new Exception(str));
}
}
4. 企业微信通知
Step 1 : 安装包,通过Nuget安装包
Install-Package NoiseNotice.Core
Install-Package NoiseNotice.Weixin
Step 2 : 配置 Startup 启动类
public class Startup
{
//...
public void ConfigureServices(IServiceCollection services)
{
//configuration
services.AddNoiseNotice(config =>
{
config.IntervalSeconds = 10;//同一标题的消息,10秒内只能发一条,避免短时间内大量发送重复消息
config.UseWeixin(option =>
{
option.WebHook = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxx";//通知地址
});
});
}
}
Step 3 : IWeixinProvider服务接口使用
[ApiController]
[Route("[controller]/[action]")]
public class NoticeController : ControllerBase
{
private readonly IWeixinProvider _weixinProvider;
public NoticeController(IWeixinProvider weixinProvider)
{
_weixinProvider = weixinProvider;
}
[HttpGet]
public async Task SendWexin([FromQuery] string str)
{
await _weixinProvider.SendAsync(str, new Exception(str));
}
}
更多示例
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Noise.Notice.Core:
Package | Downloads |
---|---|
Noise.Notice.Aliyun
Package Description |
|
Noise.Notice.Email
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 109 | 11/11/2024 |