Saladim.SalLogger 1.4.0

There is a newer version of this package available.
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                
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="Saladim.SalLogger" Version="1.4.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Saladim.SalLogger --version 1.4.0                
#r "nuget: Saladim.SalLogger, 1.4.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.
// 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,那么DebugTrace将不会被记录
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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 2.0

    • No dependencies.
  • .NETFramework 4.5.2

    • No dependencies.
  • .NETFramework 4.7.2

    • No dependencies.
  • .NETStandard 1.3

  • .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.

Version Downloads Last updated
2.0.0 111 5/24/2024
1.4.0 162 8/31/2023
1.3.0 1,006 11/28/2022
1.2.1 308 11/10/2022
1.2.0 345 11/4/2022
1.1.0 337 11/3/2022
1.0.0 340 11/3/2022

清理了很多东西, 更改了tfw到更低的版本