Longcher.Logging
1.2.3
The owner has unlisted this package.
This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Longcher.Logging --version 1.2.3
NuGet\Install-Package Longcher.Logging -Version 1.2.3
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="Longcher.Logging" Version="1.2.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Longcher.Logging" Version="1.2.3" />
<PackageReference Include="Longcher.Logging" />
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 Longcher.Logging --version 1.2.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Longcher.Logging, 1.2.3"
#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 Longcher.Logging@1.2.3
#: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=Longcher.Logging&version=1.2.3
#tool nuget:?package=Longcher.Logging&version=1.2.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Longcher.Logging
龙旗统一日志组件 - 基于 Serilog 的多目标日志框架
功能特性
- 多输出目标:控制台、文件、Elasticsearch、飞书告警
- log4net 桥接器:无需修改现有 log4net 业务代码,自动转发到 Serilog 管道
- 结构化日志:支持 JSON 格式,便于 ELK 分析
- 高性能:批量写入 ES,异步队列缓冲
- 零侵入:现有代码无需改动
安装
Install-Package Longcher.Logging
快速开始
方式一:直接使用 LogWriter
using Longcher.Logging;
using Longcher.Logging.Extensions;
// 初始化(Global.asax.cs 或 Program.cs)
var logWriter = ServiceCollectionExtensions.AddLongcherLogging();
// 写日志
logWriter.Info("用户登录成功", source: "Login", properties: new { UserId = "U001" });
logWriter.Error("数据库连接失败", ex: exception, source: "Database");
// 应用退出时释放
((IDisposable)logWriter).Dispose();
方式二:log4net 桥接(推荐现有项目使用)
只需两步,无需修改业务代码:
1. 创建 appsettings.json
{
"LogPlatform": {
"Application": "YourApp",
"EnvTag": "prod",
"FactoryCode": "Factory01"
},
"ConsoleLogging": { "Enabled": false },
"FileLogging": {
"Enabled": true,
"Path": "Logs/log-.txt",
"RollingInterval": "Day"
},
"Elasticsearch": {
"Enabled": true,
"NodeUris": "http://your-es-host:9200",
"IndexFormat": "your-app-logs-{0:yyyy.MM.dd}",
"EnableAuthentication": true,
"Username": "elastic",
"Password": "your_password"
},
"Feishu": {
"Enabled": false,
"WebhookUrl": "https://open.feishu.cn/open-apis/bot/v2/hook/xxx",
"AlertLevels": ["Error", "Fatal"]
}
}
2. 修改 log4net.config
<log4net>
<appender name="ErrorLog" type="log4net.Appender.RollingFileAppender">
</appender>
<appender name="LongcherBridge" type="Longcher.Logging.Bridge.Log4NetBridgeAppender, Longcher.Logging" />
<root>
<level value="DEBUG" />
<appender-ref ref="ErrorLog" />
<appender-ref ref="LongcherBridge" />
</root>
</log4net>
3. 初始化日志(Global.asax.cs)
protected void Application_Start()
{
// 初始化 Longcher.Logging
var logWriter = ServiceCollectionExtensions.AddLongcherLogging();
// 初始化 log4net(桥接器自动生效)
var log4netConfig = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4net.config");
log4net.Config.DOMConfigurator.Configure(new FileInfo(log4netConfig));
}
日志输出格式
Elasticsearch 字段说明
| 字段 | 说明 | 示例 |
|---|---|---|
application |
应用名称 | MES |
env_tag |
环境标识 | prod |
factory_code |
工厂编码 | Nanchang |
machine_name |
机器名 | SERVER01 |
source |
日志来源 | Login |
level |
日志级别 | Information |
message |
日志内容 | 用户登录成功 |
extend_data |
扩展数据 | {"UserId": "U001"} |
配置说明
LogPlatform
| 配置项 | 说明 | 默认值 |
|---|---|---|
| Application | 应用名称 | - |
| EnvTag | 环境标签 | dev |
| FactoryCode | 工厂编码 | Default |
| LineCode | 产线编码 | - |
| DataSource | 数据来源 | DLL |
Elasticsearch
| 配置项 | 说明 | 默认值 |
|---|---|---|
| Enabled | 是否启用 | false |
| NodeUris | ES 地址 | http://localhost:9200 |
| IndexFormat | 索引格式 | longcher-logs-{0:yyyy.MM.dd} |
| BatchPostingLimit | 批量写入条数 | 50 |
| PeriodSeconds | 刷新间隔(秒) | 2 |
| QueueLimit | 队列上限 | 100000 |
| NumberOfShards | 分片数 | 3 |
| NumberOfReplicas | 副本数 | 1 |
Feishu(飞书告警)
| 配置项 | 说明 | 默认值 |
|---|---|---|
| Enabled | 是否启用 | false |
| WebhookUrl | 飞书机器人 Webhook | - |
| AlertLevels | 告警级别 | ["Error", "Fatal"] |
系统要求
- .NET Framework 4.5.2+
- log4net 1.2.0+(桥接模式)
依赖项
- Serilog 2.12.0
- Serilog.Sinks.Console 4.1.0
- Serilog.Sinks.File 5.0.0
- Elasticsearch.Net 7.17.5
- NEST 7.17.5
- Newtonsoft.Json 13.0.3
许可证
MIT License - 龙旗科技 © 2026
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net452 is compatible. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.5.2
- Newtonsoft.Json (>= 13.0.3)
- Serilog (>= 2.12.0)
- Serilog.Sinks.Console (>= 4.1.0)
- Serilog.Sinks.File (>= 5.0.0)
- System.Buffers (>= 4.5.0)
- System.Diagnostics.DiagnosticSource (>= 5.0.0)
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 |
|---|
1.2.3 - 移除 NEST/Elasticsearch.Net 依赖,改用原生 HTTP 调用 ES,彻底兼容 .NET Framework 4.5.2+,1.2.2 - Elasticsearch.Net/NEST 降级至 7.13.1,1.2.1 - 修复文件日志路径解析问题,1.2.0 - 初始版本