YF.WL.Logger 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global YF.WL.Logger --version 1.0.1
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local YF.WL.Logger --version 1.0.1
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=YF.WL.Logger&version=1.0.1
nuke :add-package YF.WL.Logger --version 1.0.1

[TOC]

简介

YF.WL.Logger 集成自定义日志写入、查询、导出日志工具

第三方插件:SqlSugar ORM、MiniExcel、NLog、Quartz

Visual Studio 推荐安装Markdown Editor V2 扩展 或者 升级最版版本

使用说明

基础使用日志组件

services.AddWLLog();

配置信息

新建了一个wllogger.json 配置文件用来进行独立配置

{
  "WorkerId": 1, // 雪花Id 机器编码
  "File": {
    "Enabled": true, // 启用文件日志
    "MinimumLevel": "Information", // 最小日志类型
    "MaxArchiveDays": 7 // 保存天数
  },
  "Database": {
    "Enabled": true, // 启用数据库日志
    "MinimumLevel": "Information", // 最小日志类型
    "EnableInitDb": true, // 启用库表初始化
    "MaxArchiveDays": 1, // 保存天数
    "HisMaxArchiveDays": 7, // 历史保存天数
    "AutoWorkCron": "0 0 2 * * ?", // 每天凌晨2点触发 
    "ConnectionConfigs": [
      {
        "ConfigId": "default", // 正式库
        "DbType": "SqlServer", // MySql、SqlServer、Sqlite、Oracle、PostgreSQL、Dm、Kdbndp、Oscar、MySqlConnector、Access、OpenGauss、QuestDB、HG、ClickHouse、GBase、Odbc、Custom
        "ConnectionString": "server=.;uid=sa;pwd=123456;database=yf_wl_log"
      },
      {
        "ConfigId": "his", // 历史库
        "DbType": "SqlServer",
        "ConnectionString": "server=.;uid=sa;pwd=123456;database=yf_wl_log_his"
      }
    ]
  }
}

MinimumLevel 最小日志类型说明

枚举 描述
Trace 包含最详细消息的日志。这些消息可能包含敏感的应用程序数据。这些消息在默认情况下是禁用的,并且永远不应该在生产环境中启用。
Debug 在开发过程中用于交互调查的日志。这些日志应该主要包含对调试有用的信息,没有长期价值。
Information 跟踪应用程序一般流程的日志。这些日志应该具有长期价值。
Warning 应用程序流中显示异常或意外事件的日志,但不会导致应用程序停止执行。
Error 突出显示当前执行流何时因失败而停止的日志。这些应该表示当前活动中的失败,而不是应用程序范围内的失败。
Critical 描述不可恢复的应用程序或系统崩溃,或需要立即关注的灾难性故障的日志。
None 不用于写入日志信息。指定日志记录类别不应写入任何消息。

自定义日志

自定义日志 1)操作日志 需要继承 LogMessage

    /// <summary>
    /// 操作日志
    /// </summary>
    public class SysLogOp : LogMessage
    {
        /// <summary>
        /// 模块类型
        /// </summary>
        [DisplayName("模块类型")]
        public ModuleType LogType { get; set; }

        /// <summary>
        /// 方法名称
        /// </summary>
        [DisplayName("方法名称")] 
        public string MethodName { get; set; }

        /// <summary>
        /// 操作结果
        /// </summary>
        [DisplayName("操作结果")]
        public string Result { get; set; }

        /// <summary>
        /// 用户名
        /// </summary>
        [DisplayName("用户名")] 
        public string UserName { get; set; }


        public SysLogOp() { }

        public SysLogOp(ModuleType logType, string methodName, string result, string userName, string message)
        {
            LogType = logType;
            MethodName = methodName;
            Result = result;
            UserName = userName;
            Message = message;
        }
    }

公共查询

接口地址 /wl/Log/GetPagedList

请求地址
http://localhost:5010/wl/Log/GetPagedList
请求参数
{
  "PageIndex": 0,  // 页码
  "PageRows": 0,  // 每页行数
  "SortField": "Id", // 排序列
  "SortType": "desc", // 排序类型 asc、desc
  "TypeName": "string", // 类型名称 调用 GetTypeNames接口获取
  "DataBaseName": "string",// 正式库、历史库 调用 DataBaseNames接口获取
  "Search": [ // 查询条件
    {
      "FieldName": "string", // 字段名称
      "FieldValue": "string", // 字段值
      "ConditionalType": 0 // 条件类型
    }
  ],
  "StartTime": "2023-04-07T08:06:13.768Z",
  "EndTime": "2023-04-07T08:06:13.768Z"
}

ConditionalType 添加类型

枚举 枚举值 描述
Equal 0 等于
Like 1 模糊查询
GreaterThan 2 大于
GreaterThanOrEqual 3 大于等于
LessThan 4 小于
LessThanOrEqual 5 小于等于
In 6 In操作正确格式 X,Y,Z; 错误格式 'X','Y','z'
NotIn 7 Not in操作 参数和in一样
LikeLeft 8 左模糊
LikeRight 9 右模糊
NoEqual 10 不等于
IsNullOrEmpty 11 是null或者''
IsNot 12 情况1 value不等于null字段<> x情况2 value等于null 字段 is not null
NoLike 13 模糊查询取反
EqualNull 14 情况1 value不等于null字段= x情况2 value等于null 字段 is null
InLike 15 正确格式 X,Y,Z 错误格式 'X','Y','z'生在的Sql : ( id like '%X%' or id like '%Y%' or id like '%Z%')
返回结果

Data 数据列表 根据请求的TypeName不同 获取不一样的日志信息

{
  "Total": 11, // 总记录数
  "TotalPages": 2, // 总页数
  "Data": [  // 数据列表
    {
      "Id": 404228103561285,
      "ModuleType": 0,
      "MethodName": "用户登录",
      "Result": 1,
      "UserName": "LogError",
      "LogLevel": 2,
      "Message": "账号或密码不正确!",
      "LogDateTime": "2023-04-07 15:48:23",
      "RowIndex": 10
    }
  ],
  "Success": true, // 成功标识
  "ErrorCode": 0, // 错误代码 
  "Msg": null   // 返回信息
}

获取日志类型

请求地址
http://localhost:5010/wl/Log/GetLogTypeNames
请求参数

返回结果

string 数组

[
  "SysLogOp",
  "SystemLogMessage"
]

获取数据库名称

请求地址
http://localhost:5010/wl/Log/GetDatabaseNames
请求参数

返回结果
[
  {
    "Name": "defalut", // 名称
    "Remark": "正式库"  // 说明
  },
  {
    "Name": "his",
    "Remark": "历史库"
  }
]

导出Excel

请求地址
http://localhost:5010/wl/Log/DownloadExcel
请求参数

同工作查询

返回结果

数据流

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
1.0.5 135 12/9/2023
1.0.4 198 12/9/2023
1.0.3 215 12/9/2023
1.0.2 213 12/9/2023
1.0.1 297 12/9/2023
1.0.0 158 12/9/2023