XlLog.Core
1.0.4
dotnet add package XlLog.Core --version 1.0.4
NuGet\Install-Package XlLog.Core -Version 1.0.4
<PackageReference Include="XlLog.Core" Version="1.0.4" />
<PackageVersion Include="XlLog.Core" Version="1.0.4" />
<PackageReference Include="XlLog.Core" />
paket add XlLog.Core --version 1.0.4
#r "nuget: XlLog.Core, 1.0.4"
#:package XlLog.Core@1.0.4
#addin nuget:?package=XlLog.Core&version=1.0.4
#tool nuget:?package=XlLog.Core&version=1.0.4
XlLog.Core日志框架的介绍及使用
介绍
本框架基于.net6环境开发,因作者从事.net开发多年,觉得其余开源日志框架,虽功能强大,却配置繁琐,许多功能对于初学者来说也用不着,不利于小白的学习掌握,所以作者开发此XlLog.Core框架,用于快速的配置,记录日志。此框架适用于.net初学开发者,快速搭建测试用例时使用。特此说明,本框架还处于初级阶段,目前仅支持控制台打印日志,日志文件记录(仅支持时间回滚,文件大小回滚还处于待开发阶段),以及后面的数据库日志待开发。若需要特别完善和强大的日志功能,建议使用log4net等成熟框架。后续完善请诸君敬请期待🙏。
快速使用
会.net开发的应该都不陌生,搭建好项目,直接使用nuget包管理器,搜索XlLog.Core,安装到项目即可;安装好后,无需任何配置,即可使用。如下:
using XlLog.Core;
namespace NetCore.Console.Test
{
internal class TestXlLog
{
public void TestWriteLog()
{
XlLogger.Debug("Hello World");
XlLogger.Info("Hello World");
XlLogger.Warn("Hello World");
XlLogger.Error("Hello World");
XlLogger.Fatal("Hello World");
}
}
}
配置说明
本框架基于.net6.0开发,所以只支持.net6.0及以上的项目。相关配置配置在项目的程序根目录的appsettings.json配置文件即可。如下:
{
"XlLogger": {
// 日志目标:控制台(console)、文件(file)、数据库(db)(默认:txt文件 目前仅支持console和file,db还待开发)
"Target": {
"Value": "file",
// Value=file 记录文件日志时的配置
"FileSetting": {
// 日志文件路径:(默认:程序根目录log.txt 注意:路径分割符建议使用\\)
"LogPath": "LogFile\\Log.txt",
// 按执行时间回滚(秒)(默认:0 不滚动)
"InTimeRollBack": "15",
// 按文件大小回滚(kb)(默认:0 不滚动)
"InSizeRollBack": "200",
// 按天滚动日志(适用于自定义日志文件名 默认:"false")
"IsInDayRollBack":"true"
},
// Value=db 记录数据库日志时的配置
"DbSetting":{
// 数据库类型:sqlserver(目前仅支持sqlserver,其他类型数据库将来看情况更新)
"DbType":"sqlserver",
// 数据库连接字符串
"ConnectString":"Server=localhost;DataBase=XlLog;Uid=sa;Pwd=wqsj2000",
// 是否在写数据库日志的同时写文件日志 (默认值:false)
"IsSameTimeFile":"true"
}
},
// 日志级别:Debug、Info、Warn、Error、Fatal(默认:Debug)
"Level": {
"Value": "error"
},
// 日志模板:(默认:%datetime% [%level%] %message%%newLine%)
"Pattern": {
"Value": "%datetime% [%level%] %message%%newLine%"
}
}
}
更新日志
2023-12-17 版本1.0.2
1、将调用基类LogHelper改为了XlLogger,如下:
XlLogger.Debug("Hello World");
2023-12-17 版本1.0.3
1、新增支持按日志文件大小回滚(kb),默认0,不进行滚动。注意:当时间回滚和文件大小回滚都开启时,时间回滚的优先级高于文件大小回滚,如下:
// 按执行时间回滚(秒)(默认:0 不滚动)
"InTimeRollBack": "15",
// 按文件大小回滚(kb)(默认:0 不滚动)
"InSizeRollBack": "200",
2、新增支持按天回滚,按天回滚默认以天创建目录,注意仅在传入自定义日志文件标题时有效,且调用时创建一个日志文件,如下:
// 按天滚动日志(适用于自定义日志文件名 默认:"false")
"IsInDayRollBack":"true"
实例:
XlLogger.Debug("hello world", "[Debug]_标题_输入");
2023-12-17 版本1.0.4
1、新增数据库日志记录功能,因作者当前使用sqlserver数据库,所以目前仅支持sqlserver数据库,使用简单,配置如下:
// Value=db 记录数据库日志时的配置
"DbSetting":{
// 数据库类型:sqlserver(目前仅支持sqlserver,其他类型数据库将来看情况更新)
"DbType":"sqlserver",
// 数据库连接字符串
"ConnectString":"Server=localhost;DataBase=*;Uid=*;Pwd=*",
// 是否在写数据库日志的同时写文件日志 (默认值:false)
"IsSameTimeFile":"true"
}
实例:
1、创建一个日志表(只为演示插入日志,具体字段内容请忽略)如下:
USE [XlLog]
GO
/****** Object: Table [dbo].[InterFaceLog] Script Date: 2023-12-17 21:17:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[InterFaceLog](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NULL,
[Age] [int] NULL,
[IsUse] [bit] NULL,
[CreateTime] [datetime] NULL,
CONSTRAINT [PK_InterFaceLog] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
2、创建一个日志信息实体类(类名与属性名必须全部与数据表一一对应,目前没有做映射关系维护,后面也不太想做,就是为了简单)如下:
public class InterfaceLog
{
// 此特性是为了表示自增ID
[XlLogColumn(IsIdentity = true)]
public int ID { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public bool IsUse { get; set; }
public DateTime CreateTime { get; set; }
}
3、调用日志,如下:
XlLogger.Debug(new InterfaceLog
{
ID = 10,
Name = "张三",
Age =25,
IsUse = false,
CreateTime = DateTime.Now,
});
4、如果想获取日志数据库链接字符串,如下:
XlLogger.GetConnectString((string connStr) =>
{
Console.WriteLine(connStr);
});
输出内容:"Server=localhost;DataBase=*;Uid=*;Pwd=*"
5、如果想在代码中修改数据库连接字符串,如下:
XlLogger.GetConnectString((string connStr) =>
{
string newConnStr = "Server=localhost;DataBase=*;Uid=*;Pwd=*";
XlLogger.SetConnectString(newConnStr);
});
| 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. |
-
net6.0
- System.Data.SqlClient (>= 4.8.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.4 | 258 | 12/17/2023 |