UltimateLogSystem 1.1.0
dotnet add package UltimateLogSystem --version 1.1.0
NuGet\Install-Package UltimateLogSystem -Version 1.1.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="UltimateLogSystem" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="UltimateLogSystem" Version="1.1.0" />
<PackageReference Include="UltimateLogSystem" />
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 UltimateLogSystem --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: UltimateLogSystem, 1.1.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.
#:package UltimateLogSystem@1.1.0
#: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=UltimateLogSystem&version=1.1.0
#tool nuget:?package=UltimateLogSystem&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
终极日志系统
这是一个功能全面的.NET日志系统,支持多种日志级别、多种输出格式、多种输出目标,以及丰富的扩展功能。
主要特性
- 多级别日志:支持Trace、Debug、Info、Warning、Error、Fatal等预定义级别,也支持自定义日志级别
- 实时日志记录:通过后台线程处理,不阻塞主线程
- 时间戳:每条日志都附带精确时间戳
- 滚动文件更新:支持按大小自动滚动更新日志文件
- 日期滚动日志:支持按日期创建新文件,同一天多次启动应用时自动创建不同的日志文件
- 自定义头信息:可以为日志添加自定义类别和属性
- 多格式支持:支持文本、JSON、XML等多种格式
- 内置解析器:支持解析各种格式的日志文件
- 彩色输出:控制台输出支持不同颜色
- 事件响应:支持根据日志级别或内容触发不同操作
- 上下文支持:支持日志上下文,方便跟踪请求
- 结构化日志:支持记录结构化数据
- 性能监控:内置操作计时功能
- 导入导出:支持导入导出各种格式的日志
快速开始
安装
dotnet add package UltimateLogSystem
基本用法
// 创建日志配置
var config = new LoggerConfiguration()
.SetMinimumLevel(LogLevel.Info)
.AddConsoleWriter()
.AddFileWriter("logs/app.log");
// 创建日志记录器
var logger = LoggerFactory.CreateLogger(config);
// 记录日志
logger.Info("应用程序启动成功");
logger.Warning("发现潜在问题");
logger.Error("发生错误", exception: ex);
// 关闭日志系统
LoggerFactory.CloseAll();
高级用法
// 创建更复杂的配置
var config = new LoggerConfiguration()
.SetMinimumLevel(LogLevel.Trace)
.SetDefaultCategory("MyApp")
.AddConsoleWriter(new TextFormatter("[{timestamp}] [{level}] {message}"))
.AddFileWriter("logs/app.log", maxFileSize: 5 * 1024 * 1024, maxRollingFiles: 10)
.AddFileWriter("logs/app.json", new JsonFormatter())
.AddEmailNotification(
"smtp.example.com", 587,
"alerts@example.com", "admin@example.com",
"username", "password",
LogLevel.Error);
// 使用上下文属性
LogContext.SetProperty("UserId", "12345");
logger.Info("用户登录成功");
// 结构化日志
logger.LogStructured(LogLevel.Info, "用户 {UserName} 执行了 {Action}",
new { UserName = "张三", Action = "登录" });
// 性能监控
logger.Time(() => {
// 执行耗时操作
}, "数据库查询");
扩展
自定义输出目标
public class MyCustomWriter : ILogWriter
{
public void Write(LogEntry entry)
{
// 自定义日志处理逻辑
}
public void Flush() { }
public void Dispose() { }
}
// 使用自定义输出
config.AddWriter(new MyCustomWriter());
自定义格式化器
public class MyFormatter : ILogFormatter
{
public string Format(LogEntry entry)
{
// 自定义格式化逻辑
return $"自定义格式: {entry.Message}";
}
}
// 使用自定义格式化器
config.AddConsoleWriter(new MyFormatter());
许可证
Apache 2.0
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 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.
-
.NETStandard 2.0
- Microsoft.CSharp (>= 4.7.0)
- Microsoft.Data.Sqlite (>= 3.1.32)
- Newtonsoft.Json (>= 13.0.1)
- System.Collections (>= 4.3.0)
- System.Console (>= 4.3.1)
- System.Data.Common (>= 4.3.0)
- System.Data.SqlClient (>= 4.8.6)
- System.Data.SQLite (>= 1.0.117)
- System.Drawing.Common (>= 4.7.2)
- System.IO (>= 4.3.0)
- System.IO.FileSystem (>= 4.3.0)
- System.Linq (>= 4.3.0)
- System.Net.Http (>= 4.3.4)
- System.Runtime.Extensions (>= 4.3.1)
- System.Text.Json (>= 8.0.5)
- System.Text.RegularExpressions (>= 4.3.1)
- System.Threading.Tasks.Extensions (>= 4.5.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
First Release