SfeWork.Log
1.0.5
dotnet add package SfeWork.Log --version 1.0.5
NuGet\Install-Package SfeWork.Log -Version 1.0.5
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="SfeWork.Log" Version="1.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SfeWork.Log" Version="1.0.5" />
<PackageReference Include="SfeWork.Log" />
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 SfeWork.Log --version 1.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SfeWork.Log, 1.0.5"
#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 SfeWork.Log@1.0.5
#: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=SfeWork.Log&version=1.0.5
#tool nuget:?package=SfeWork.Log&version=1.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
简单的日志组件,支持自动清理,日志文件分割
1、快速开始
var logService = new SfeWork.Log("Logs");
例如设定的主目录为Logs,将按照
Logs/yyyy/MM/dd/HH.txt的路径进行存储
2、参数配置
var logService = new SfeWork.Log("Logs")
{
RetentionDays = 90, //日志保留天数,单位天,默认空,不进行清理
ArchiveAboveSize = 1 //日志文件分割大小,单位M,默认空,不进行分割
};
日志保留天数:如设置为90,则只保留90天以内的日志,超过90天的日志将被自动删除。
注意:删除策略是由日志写入操作触发,也就是说只有当有日志写入操作时才会进行检测是否需要执行删除,24小时内只会执行一次。
日志文件分割大小:按照设定的文件大小进行分割。
注意:设定日志文件分割后,将按照
Logs/yyyy/MM/dd/HH_{分割计次}.txt的路径进行存储
3、自定义日志记录事件回调
var logService = new SfeWork.Log("Logs");
logService.OnRecord += OnRecord;
public void OnRecord(Log.Model log)
{
Console.WriteLine($"记录时间:{log.Time}");
Console.WriteLine($"日志内容:{log.Message}");
Console.WriteLine($"日志类型:{log.LogType}");
}
4、使用方法
var logService = new SfeWork.Log("Logs");
logService.Info("日志内容");
logService.Debug("日志内容");
logService.Warning("日志内容");
logService.Error("日志内容");
var logService = new SfeWork.Log("Logs");
try
{
...
}
catch (Exception ex)
{
logService.Error(ex);
}
5、其他
- 日志类型:Info、Debug、Warning、Error
| 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 | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- System.Threading.Channels (>= 10.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.5 | 83 | 3/29/2026 |