XlLog 1.0.8

dotnet add package XlLog --version 1.0.8
                    
NuGet\Install-Package XlLog -Version 1.0.8
                    
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="XlLog" Version="1.0.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="XlLog" Version="1.0.8" />
                    
Directory.Packages.props
<PackageReference Include="XlLog" />
                    
Project file
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 XlLog --version 1.0.8
                    
#r "nuget: XlLog, 1.0.8"
                    
#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 XlLog@1.0.8
                    
#: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=XlLog&version=1.0.8
                    
Install as a Cake Addin
#tool nuget:?package=XlLog&version=1.0.8
                    
Install as a Cake Tool

XlLog日志框架的介绍及使用

介绍

本框架基于.net4.0环境开发,因作者从事.net开发多年,觉得其余开源日志框架,虽功能强大,却配置繁琐,许多功能对于初学者来说也用不着,不利于小白的学习掌握,所以作者开发此XlLog框架,用于快速的配置,记录日志。此框架适用于.net初学开发者,快速搭建测试用例时使用。特此说明,本框架还处于初级阶段,目前支持控制台打印日志,日志文件记录(支持时间回滚,文件大小回滚),数据库日志记录。若需要特别完善和强大的日志功能,建议使用log4net等成熟框架。(本框架适用于.net4.0以上的framework项目,若是.net6版本以上项目,可以使用XlLog.Core包)

快速使用

会.net开发的应该都不陌生,搭建好项目,直接使用nuget包管理器,搜索XlLog,安装到项目即可;安装好后,无需任何配置,即可使用。如下:

using XlLog;

namespace Net.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");
        }
    }
}
配置说明

本框架基于.net4.0开发,所以只支持.net4.0及以上的framework项目。配置文件采用xml节点配置,无需再单独设置配置文件,相关配置配置在项目的程序根目录的app.config或者web.config配置文件即可。如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
	<configSections>
		<section name="xllogger" type="System.Configuration.IgnoreSectionHandler" allowLocation="false" />
	</configSections>
	<xllogger>
        
		<target value="file">
            
			<fileSetting>
                
				<logPath value="LogFile\xllog.txt" />
                
                <isFileInDayRollBack value="true" />
                
				<inTimeRollBack value="0" />
                
				<inSizeRollBack value="200" />
                
				<isInDayRollBack value="true" />
			</fileSetting>
            
			<dbSetting>
                
				<dbType value="sqlserver" />
                
				<connectString value="Server=localhost;DataBase=XlLog;Uid=*;Pwd=*" />
                
				<isSameTimeFile value="true" />
			</dbSetting>
		</target>
        
		<level value="debug" />
        
		<pattern value="%datetime% [%level%] %message% %newLine%" />
	</xllogger>
</configuration>

注意因为是配置在项目的config文件中,所以xml读取,必须在config文件中设置如下节点:

<configSections>
		<section name="xllogger" type="System.Configuration.IgnoreSectionHandler" allowLocation="false" />
</configSections>
功能介绍

1、按日志文件大小回滚(kb),默认0,不进行滚动。注意:当时间回滚和文件大小回滚都开启时,时间回滚的优先级高于文件大小回滚,如下:


<inTimeRollBack value="0" />

<inSizeRollBack value="200" />

2、按天回滚,按天回滚默认以天创建目录,注意仅在传入自定义日志文件标题时有效,且调用时创建一个日志文件,如下:


<isInDayRollBack value="true" />

实例:

 XlLogger.Debug("hello world", "[Debug]_标题_输入");

alternate text is missing from this package README image

3、数据库日志记录,因作者当前使用sqlserver数据库,所以目前仅支持sqlserver数据库,使用简单,配置如下:


<dbSetting>
    
	<dbType value="sqlserver" />
    
	<connectString value="Server=localhost;DataBase=XlLog;Uid=*;Pwd=*" />
    
	<isSameTimeFile value="true" />
</dbSetting>

实例:

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 Compatible and additional computed target framework versions.
.NET Framework net40 is compatible.  net403 was computed.  net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.0

    • No dependencies.

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.8 231 6/30/2024
1.0.7 202 1/3/2024