HMENetCore.Extensions
6.0.51
dotnet add package HMENetCore.Extensions --version 6.0.51
NuGet\Install-Package HMENetCore.Extensions -Version 6.0.51
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HMENetCore.Extensions" Version="6.0.51" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HMENetCore.Extensions" Version="6.0.51" />
<PackageReference Include="HMENetCore.Extensions" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add HMENetCore.Extensions --version 6.0.51
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: HMENetCore.Extensions, 6.0.51"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package HMENetCore.Extensions@6.0.51
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=HMENetCore.Extensions&version=6.0.51
#tool nuget:?package=HMENetCore.Extensions&version=6.0.51
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
HMENetCore.Extensions
简介
HMENetCore.Extensions
是一个功能丰富的 .NET Core 扩展库,集成了日志记录、路由配置、IP限流、配置管理等多种常用功能。该库旨在简化开发流程,提高开发效率,同时保持代码的整洁和可维护性。
功能特性
- NLog 日志集成:增强的 NLog 日志记录功能
- 全局异常处理:统一的异常处理中间件
- 模型验证:自定义模型验证响应格式
- 集中式路由:全局路由前缀配置
- IP 限流:防止过度请求的保护机制
- 自定义配置:JSON 配置文件管理
- 静态配置访问:全局访问应用配置
.NET支持
- 跨平台支持: Supports .NET Standard 2.1, .NET 6, .NET 8, and .NET 9.
安装
dotnet add package HMENetCore.Extensions --version 6.0.50
使用说明
1. NLog 日志集成
服务注册
// 使用默认配置
services.AddNLogSingleton();
// 或使用自定义配置
services.AddNLogSingleton(config => {
// 自定义 NLog 配置
});
使用示例
public class MyService
{
private readonly INLogHelper _logger;
public MyService(INLogHelper logger)
{
_logger = logger;
}
public void DoWork()
{
try {
// 业务逻辑
_logger.Info(this, "工作正常完成");
}
catch (Exception ex) {
_logger.Error(this, "工作发生错误", ex);
}
}
}
2. 全局异常处理
- 统一异常处理格式
- 支持开发环境详细错误信息
- 集成 NLog 记录异常
服务注册
services.AddControllers(options => {
options.Filters.Add<GlobalExceptionsFilter>();
});
3. 集中式路由
服务注册
services.AddControllers(options => {
options.UseCentralRoutePrefix(new RouteAttribute("api/v1"));
});
4. IP 限流
appsettings.json 配置
{
"IpRateLimiting": {
"EnableEndpointRateLimiting": true,
"StackBlockedRequests": false,
"RealIpHeader": "X-Real-IP",
"ClientIdHeader": "X-ClientId",
"HttpStatusCode": 429,
"GeneralRules": [
{
"Endpoint": "*",
"Period": "1s",
"Limit": 5
}
]
}
}
服务注册
services.AddIpPolicyRateLimit(Configuration.GetSection("IpRateLimiting"));
app.UseIpLimit();
5. 自定义配置管理
加载自定义 JSON 配置
builder.Configuration.AddJsonFileBuilder(AppDomain.CurrentDomain.BaseDirectory + "Config");
// 在应用启动时配置
AppSettingsHelper.AppSettingsConfigure(Configuration);
使用静态配置访问
// 任何地方访问配置
var setting = AppSettingsHelper.GetValue("ConnectionStrings:Default");
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- AspNetCoreRateLimit (>= 5.0.0)
- HMENetCore (>= 6.0.48)
- NLog.Extensions.Logging (>= 6.0.3)
-
net8.0
- AspNetCoreRateLimit (>= 5.0.0)
- HMENetCore (>= 6.0.48)
- NLog.Extensions.Logging (>= 6.0.3)
-
net9.0
- AspNetCoreRateLimit (>= 5.0.0)
- HMENetCore (>= 6.0.48)
- NLog.Extensions.Logging (>= 6.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
6.0.51 | 129 | 8/11/2025 |
6.0.50 | 128 | 8/11/2025 |
6.0.49 | 211 | 8/7/2025 |
6.0.48 | 127 | 7/16/2025 |
6.0.47 | 145 | 7/8/2025 |
6.0.46 | 148 | 7/2/2025 |
6.0.45 | 154 | 6/27/2025 |
6.0.42 | 152 | 6/18/2025 |
6.0.40 | 274 | 6/10/2025 |
6.0.39 | 243 | 5/15/2025 |
6.0.35 | 177 | 4/24/2025 |
6.0.33 | 197 | 4/11/2025 |
6.0.32 | 194 | 4/9/2025 |
6.0.31 | 174 | 3/17/2025 |
6.0.30 | 149 | 2/19/2025 |
6.0.15 | 135 | 12/30/2024 |
6.0.12 | 140 | 11/28/2024 |
6.0.11 | 133 | 11/18/2024 |
6.0.9 | 135 | 11/15/2024 |
6.0.6 | 150 | 10/9/2024 |
6.0.3 | 150 | 9/9/2024 |
6.0.2 | 146 | 8/28/2024 |
6.0.1 | 164 | 8/16/2024 |