Saladim.SalLogger
1.0.0
See the version list below for details.
dotnet add package Saladim.SalLogger --version 1.0.0
NuGet\Install-Package Saladim.SalLogger -Version 1.0.0
<PackageReference Include="Saladim.SalLogger" Version="1.0.0" />
paket add Saladim.SalLogger --version 1.0.0
#r "nuget: Saladim.SalLogger, 1.0.0"
// Install Saladim.SalLogger as a Cake Addin #addin nuget:?package=Saladim.SalLogger&version=1.0.0 // Install Saladim.SalLogger as a Cake Tool #tool nuget:?package=Saladim.SalLogger&version=1.0.0
Saladim.SalLogger
<div align="middle"> 一个被建议用于游戏/小框架的轻量级日志框架 </div>
构建 Build
本项目使用Visual Studio 2022创建,面向.net standard2.1
,.net core 3.1
,.net 6.0
使用vs2022的默认构建方法即可
使用 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 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 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 | netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 3.1
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
-
net6.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.
初始化 Init