CSoft.LogInterface
11.0.0
dotnet add package CSoft.LogInterface --version 11.0.0
NuGet\Install-Package CSoft.LogInterface -Version 11.0.0
<PackageReference Include="CSoft.LogInterface" Version="11.0.0" />
<PackageVersion Include="CSoft.LogInterface" Version="11.0.0" />
<PackageReference Include="CSoft.LogInterface" />
paket add CSoft.LogInterface --version 11.0.0
#r "nuget: CSoft.LogInterface, 11.0.0"
#:package CSoft.LogInterface@11.0.0
#addin nuget:?package=CSoft.LogInterface&version=11.0.0
#tool nuget:?package=CSoft.LogInterface&version=11.0.0
CSoft.LogInterface
为 .NET 应用和类库提供日志抽象。业务代码通过 ILogFactory 获取 ILogger,由应用启动代码选择具体日志后端。
安装
dotnet add package CSoft.LogInterface --version 11.0.0
包内包含 netstandard2.0、net8.0、net9.0、net10.0 和 net11.0 的程序集及 XML API 文档。
记录日志
using LogInterface;
ILogger logger = Logs.LogFactory.GetLogger("Jobs");
logger.Info("开始处理任务");
logger.Info("任务 {0} 已完成", 42);
logger.Info(new { JobId = 42, Status = "Completed" });
if (logger.IsDebugEnabled)
logger.Debug("记录额外的调试信息");
也可通过 GetLogger<T>() 或 GetLogger(typeof(T)) 按类型获取 logger。ILogger 提供 Trace、Debug、Info、Warn、Error 和 Fatal 六个级别,以及相应的 Is…Enabled 属性。每个级别都支持文本、复合格式字符串、对象和异常,输出格式由日志后端决定。
配置日志工厂
Logs.LogFactory 默认使用 NoOpLogFactory,所有级别均禁用。应用可以在启动时赋值为具体后端,例如 CSoft.LoggerNLog 的 NLogFactory。使用依赖注入时,业务类可直接接收 ILogFactory。
替换 Logs.LogFactory 时,旧工厂若实现了 IDisposable,会先被释放。替换完成后需要重新获取已缓存的 ILogger。旧工厂释放失败时,异常会向调用方传播,默认空操作工厂将接管后续请求。
实现日志后端
后端实现 ILogFactory,并返回实现 ILogger 的实例。继承 LoggerBase 可复用级别判断、复合格式化及重载分派,后端只需提供级别启用状态和四个 Log 重载。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 is compatible. 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. net11.0 is compatible. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
-
net10.0
- No dependencies.
-
net11.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (7)
Showing the top 5 NuGet packages that depend on CSoft.LogInterface:
| Package | Downloads |
|---|---|
|
CSoft.Communication
通信物理口封装 |
|
|
CSoft.Parser
数据分帧解析器 |
|
|
CSoft.Crow
数据收发队列 |
|
|
CSoft.LoggerNLog
使用NLog输出日志 |
|
|
CSoft.CommTask
通信队列核心层(Crow/Pigeon/Sparrow) |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 11.0.0 | 262 | 11/11/2026 | |
| 10.0.0 | 16,862 | 11/12/2025 | |
| 9.0.0 | 13,747 | 11/22/2024 | |
| 8.0.0 | 11,320 | 11/15/2023 | |
| 7.0.0 | 11,639 | 11/9/2022 | |
| 6.0.3 | 11,307 | 9/23/2022 | |
| 6.0.2 | 11,297 | 5/12/2022 | |
| 6.0.1 | 2,009 | 3/15/2022 | |
| 6.0.0 | 3,123 | 11/9/2021 | |
| 5.0.3 | 1,684 | 8/18/2021 | |
| 5.0.2 | 4,020 | 1/22/2021 | |
| 5.0.0 | 2,835 | 11/18/2020 | |
| 1.0.0 | 4,072 | 6/30/2020 |
新增 .NET 11 支持