Net.LoongTech.Bedrock.LoggingV2
1.1.2
dotnet add package Net.LoongTech.Bedrock.LoggingV2 --version 1.1.2
NuGet\Install-Package Net.LoongTech.Bedrock.LoggingV2 -Version 1.1.2
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="Net.LoongTech.Bedrock.LoggingV2" Version="1.1.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Net.LoongTech.Bedrock.LoggingV2" Version="1.1.2" />
<PackageReference Include="Net.LoongTech.Bedrock.LoggingV2" />
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 Net.LoongTech.Bedrock.LoggingV2 --version 1.1.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Net.LoongTech.Bedrock.LoggingV2, 1.1.2"
#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 Net.LoongTech.Bedrock.LoggingV2@1.1.2
#: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=Net.LoongTech.Bedrock.LoggingV2&version=1.1.2
#tool nuget:?package=Net.LoongTech.Bedrock.LoggingV2&version=1.1.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
LoggingV2
重写版日志组件,目标:
- 按目录保存:
<RootDirectory>/<Category>/ - 一天一个文件:
log-YYYY-MM-DD.txt/err-YYYY-MM-DD.txt - 异步批量写盘,降低业务线程阻塞
快速使用(静态方式)
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.Build();
LoggerHelperV2.InitLoggerFactory(config, options =>
{
options.RootDirectory = "Logs";
options.MinLevel = LogLevel.Information;
options.QueueCapacity = 100000;
options.BatchSize = 200;
});
var logger = LoggerHelperV2.CreateLogger("ZBSJSTelnet_Receive");
logger.LogInformation("hello");
LoggerHelperV2.Shutdown();
DI 方式(推荐)
var host = Host.CreateDefaultBuilder(args)
.ConfigureServices((ctx, services) =>
{
services.AddBedrockLoggingV2(options =>
{
options.RootDirectory = "Logs";
options.MinLevel = LogLevel.Information;
options.QueueCapacity = 100000;
options.BatchSize = 200;
});
})
.Build();
注册后即可在任何服务中直接注入:
public class Worker
{
private readonly ILogger<Worker> _logger;
public Worker(ILogger<Worker> logger)
{
_logger = logger;
}
}
说明
- 保持“分目录 + 按天文件”行为。
Log()内只入队,不做同步文件写入。- 程序关闭时调用
Shutdown(),确保队列尽量落盘。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. net9.0 was computed. 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 was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- Microsoft.Extensions.Hosting (>= 6.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.