Saladim.SalLogger 2.0.0

dotnet add package Saladim.SalLogger --version 2.0.0
NuGet\Install-Package Saladim.SalLogger -Version 2.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="Saladim.SalLogger" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Saladim.SalLogger --version 2.0.0
#r "nuget: Saladim.SalLogger, 2.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.
// Install Saladim.SalLogger as a Cake Addin
#addin nuget:?package=Saladim.SalLogger&version=2.0.0

// Install Saladim.SalLogger as a Cake Tool
#tool nuget:?package=Saladim.SalLogger&version=2.0.0

Saladim.SalLogger

<div align="middle"> 一个被建议用于游戏/小框架的轻量级日志框架 (或者叫做代码片段更合适)<br> A lightweight logging framework (or better called a code snippet) recommended for games/small frameworks. </div>

引用 Reference

你可以到 NuGet 上搜索 SalLogger 以 NuGet 包形式安装, 或者直接引入项目全代码(在 gist 中)
You can search for SalLogger on NuGet to install it as a NuGet package, or directly include the entire project code (available on gist).

构建 Build

项目本体很简单, 只需要简单的 dotnet build / 点 IDE 的一下 生成 键.
The project itself is very simple, just use dotnet build or click the Build button in your IDE.

使用 Usage

核心类为 Logger, 位于 Saladim.SalLogger 命名空间下, 可以使用构造器直接构造一个 Logger:
The core class is Logger, located in the Saladim.SalLogger namespace. You can directly instantiate a Logger using its constructor:

Logger logger = new Logger(LogLevel.Info);
logger.AddLogHandler(Console.WriteLine);

构造器的 LogLevel 类型的参数限制了 Logger 输出的最低等级, 日志等级 LogLevel 分为:
The constructor's LogLevel parameter sets the minimum logging level for the Logger. The LogLevel enum has the following levels:

  • Trace
  • Debug
  • Info
  • Warn
  • Error
  • Fatal

如果将限制等级设置为 Info, 那么 DebugTrace 将不会被记录, 其余同理.
If you set the logging level to Info, Debug and Trace messages will not be recorded. The same applies to other levels.

Logger 对象有许多重载方法, 可以选择适合情景的重载版本:
The Logger class provides various overloaded methods to suit different scenarios:

logger.Log(LogLevel.Info, "SectionName", "Your log message.");
logger.Log(LogLevel.Warn, "SectionName", "SubsectionName", "Your log message.");
logger.LogInfo("SectionName", "Easier way to log info message.");
logger.LogFatal("SectionName", "Subsection", "Easier way to log fatal message with subsection.");
logger.LogTrace("SectionName", "This log message will not be logged because we limit the `LevelLimit` to `Info`");

将会产生如下输出(控制台):
This will produce the following output (in the console):

[20:47:45.9] [Info:SectionName]: Your log message.
[20:47:45.9] [Warn:SectionName/SubsectionName]: Your log message.
[20:47:45.9] [Info:SectionName]: Easier way to log info message.
[20:47:45.9] [Fatal:SectionName/Subsection]: Easier way to log fatal message with subsection.

更多实例 More Examples

如果你不满足于目前的日志格式, 那么你可以使用 AddLogHandlerLogHandler 重载, 它会将传递所有的原始日志参数, 例如你可以获取其中的 logLevel 参数并对日志上色.
If you are not satisfied with the current log format, you can use the LogHandler overload of AddLogHandler. This method passes all the original log parameters, allowing you to customize the log format, such as coloring the logs based on the logLevel.

LogHandler 原型如下:
The LogHandler delegate is defined as follows:

public delegate void LogHandler(LogLevel logLevel, string section, string? subsection, string content);

当未指定 subsectionnull 会被传入.
When the subsection is not specified, null will be passed.

此外还可以只单独指定格式化器, 例如使用如下格式化器实例:
You can also specify only a formatter, like the following example:

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}";

并使用 AddLogHandler(FormattedLogHandler, LogFormatter) 重载, 可以得到以下日志:
Using the (FormattedLogHandler, LogFormatter) overload of AddLogHandler, you can achieve logs like this:

「21:01:25.6 Info SomeSection」 This is a log
「21:01:25.6 Fatal SomeSection」 Another fatal log

更多内容 Additional Information

Logger 还可以接受一个 Exception 对象作为内容并可选地指定一个前缀 prefix. 实例请见 Sample/Program.cs 文件.
The Logger can also accept an Exception object as the log content and optionally specify a prefix. For examples, see the Sample/Program.cs file.

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 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. 
.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.0 is compatible.  netstandard1.1 was computed.  netstandard1.2 was computed.  netstandard1.3 was computed.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net35 is compatible.  net40 was computed.  net403 was computed.  net45 was computed.  net451 was computed.  net452 is compatible.  net46 was computed.  net461 was computed.  net462 is compatible.  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. 
Windows Phone wp8 was computed.  wp81 was computed.  wpa81 was computed. 
Windows Store netcore was computed.  netcore45 was computed.  netcore451 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 3.5

    • No dependencies.
  • .NETFramework 4.5.2

    • No dependencies.
  • .NETFramework 4.6.2

    • No dependencies.
  • .NETFramework 4.7.2

    • No dependencies.
  • .NETStandard 1.0

  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.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 71 5/24/2024
1.4.0 135 8/31/2023
1.3.0 916 11/28/2022
1.2.1 283 11/10/2022
1.2.0 318 11/4/2022
1.1.0 311 11/3/2022
1.0.0 319 11/3/2022

Clean up