CSoft.LogInterface 11.0.0

dotnet add package CSoft.LogInterface --version 11.0.0
                    
NuGet\Install-Package CSoft.LogInterface -Version 11.0.0
                    
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="CSoft.LogInterface" Version="11.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CSoft.LogInterface" Version="11.0.0" />
                    
Directory.Packages.props
<PackageReference Include="CSoft.LogInterface" />
                    
Project file
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 CSoft.LogInterface --version 11.0.0
                    
#r "nuget: CSoft.LogInterface, 11.0.0"
                    
#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 CSoft.LogInterface@11.0.0
                    
#: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=CSoft.LogInterface&version=11.0.0
                    
Install as a Cake Addin
#tool nuget:?package=CSoft.LogInterface&version=11.0.0
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .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.

新增 .NET 11 支持