Saladim.SalLogger
1.4.0
See the version list below for details.
dotnet add package Saladim.SalLogger --version 1.4.0
NuGet\Install-Package Saladim.SalLogger -Version 1.4.0
<PackageReference Include="Saladim.SalLogger" Version="1.4.0" />
paket add Saladim.SalLogger --version 1.4.0
#r "nuget: Saladim.SalLogger, 1.4.0"
// Install Saladim.SalLogger as a Cake Addin #addin nuget:?package=Saladim.SalLogger&version=1.4.0 // Install Saladim.SalLogger as a Cake Tool #tool nuget:?package=Saladim.SalLogger&version=1.4.0
Saladim.SalLogger
<div align="middle"> 一个被建议用于游戏/小框架的轻量级日志框架 </div>
引用
你可以到nuget上搜索SalLogger以nuget包形式安装, 或者直接引入项目全代码(在gist中)
构建 Build
项目本体很简单, 只需要简单的 dotnet build
/ IDE的一下生成
键.
使用 Usage
核心类为Logger
,位于Saladim.SalLogger
命名空间下,
在开始记录日志前应该创建同命名空间的LoggerBuilder
建造器,例如:
LoggerBuilder builder = new();
builder.WithLevelLimit(LogLevel.Trace)
.WithLogToConsole();
WithLevelLimit
限制了将被建造了logger真正输出日志的最低等级,日志等级(LogLevel
)分为:
- Trace
- Debug
- Info
- Warn
- Error
- Fatal
如果将限制等级设置为Info
,那么Debug
与Trace
将不会被记录
WithLogToConsole
指示建造器应该将这个输出到控制台上
配置完建造器后可使用建造器的Build
方法获取一个Logger
对象:
Logger logger = builder.Build();
Logger
对象有许多重载方法,你可以选择适合情景的重载版本
例如如下实例:
logger.Log(LogLevel.Info, "sectionName", "Your log message.");
logger.Log(LogLevel.Warn, "sectionName", "subSectionName", "Your log message.");
logger.LogInfo("sectionName", "easier to log info message.");
logger.LogFatal("sectionName", "subSection", "you can also have `subSection` in easier way.");
logger.LogTrace("sectionName", "this log message will not be logged because we limit the `LevelLimit` to `Info`");
将会产生如下输出(控制台):
[20:56:33.2] [Info:sectionName]: Your log message.
[20:56:33.3] [Warn:sectionName/subSectionName]: Your log message.
[20:56:33.3] [Info:sectionName]: easier to log info message.
[20:56:33.3] [Fatal:sectionName/subSection]: you can also have `subSection` in easier way.
更多实例
如果你不满足于目前的日志格式,那么你可以使用建造器的WithFormatter
方法指定格式化器,
该方法接受一个LogFormatter委托实例,原型如下:
public delegate string LogFormatter(LogLevel logLevel,string section,string? subSection,string content);
特别注意,当未指定subSection
时会将null
传入
例如使用如下格式化器实例:
static string MyFormatter(LogLevel logLevel, string section, string subSection, string content)
=> $"「{DateTime.Now.TimeOfDay:hh\\:mm\\:ss\\.f} {logLevel} {section}" +
$"{(subSection is null ? "" : $"/{subSection}")}」 {content}";
会产生如下所示的日志效果:
「21:01:25.6 Info SomeSection」 这是一条log
「21:01:25.6 Fatal SomeSection」 另一条fatal log
更多内容
Logger
接受一个Exception
对象作为内容,同时加入前缀和后缀
实例请见Sample/Program.cs
文件
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. 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 is compatible. 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 was computed. 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. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.3 is compatible. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net20 is compatible. net35 was computed. net40 was computed. net403 was computed. net45 was computed. net451 was computed. net452 is compatible. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 is compatible. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 2.0
- No dependencies.
-
.NETFramework 4.5.2
- No dependencies.
-
.NETFramework 4.7.2
- No dependencies.
-
.NETStandard 1.3
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 2.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Saladim.SalLogger:
Package | Downloads |
---|---|
SaladimQBot.GoCqHttp
SaladimQBot的使用go-cqhttp实现 |
GitHub repositories
This package is not used by any popular GitHub repositories.
清理了很多东西, 更改了tfw到更低的版本