From c45287fae0252bda4df9b828478753dd70e4560a Mon Sep 17 00:00:00 2001 From: "David P.G" Date: Thu, 4 Sep 2025 14:52:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A5=E5=BF=97=E5=86=99?= =?UTF-8?q?=E5=85=A5=E6=95=B0=E6=8D=AE=E5=BA=93=E5=A4=B1=E8=B4=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DMS.Infrastructure/Entities/DbNlog.cs | 50 ------------------- .../Repositories/InitializeRepository.cs | 1 - DMS.WPF/Configurations/nlog.config | 27 +++++++--- 3 files changed, 21 insertions(+), 57 deletions(-) delete mode 100644 DMS.Infrastructure/Entities/DbNlog.cs diff --git a/DMS.Infrastructure/Entities/DbNlog.cs b/DMS.Infrastructure/Entities/DbNlog.cs deleted file mode 100644 index 61ab977..0000000 --- a/DMS.Infrastructure/Entities/DbNlog.cs +++ /dev/null @@ -1,50 +0,0 @@ -using SqlSugar; -using System; - -namespace DMS.Infrastructure.Entities; - -/// -/// 数据库实体:对应数据库中的 Logs 表,用于存储应用程序日志。 -/// -public class DbNlog -{ - [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] - public long Id { get; set; } - - /// - /// 日志记录的时间戳。 - /// - public DateTime Logged { get; set; } - - /// - /// 日志级别 (e.g., "Info", "Warn", "Error", "Debug")。 - /// - public string Level { get; set; } - - /// - /// 日志消息主体。 - /// - [SugarColumn(Length = -1)] // 映射为NVARCHAR(MAX)或类似类型 - public string Message { get; set; } - - /// - /// 异常信息,包括堆栈跟踪。如果无异常则为null。 - /// - [SugarColumn(IsNullable = true, Length = -1)] - public string Exception { get; set; } - - /// - /// 记录日志的调用点信息 (文件路径:行号)。 - /// - public string CallSite { get; set; } - - /// - /// 记录日志的方法名。 - /// - public string MethodName { get; set; } - - /// - /// (用于聚合) 此条日志在指定时间窗口内被触发的总次数。默认为1。 - /// - public int AggregatedCount { get; set; } = 1; -} \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/InitializeRepository.cs b/DMS.Infrastructure/Repositories/InitializeRepository.cs index 0a2aad4..47d2aaf 100644 --- a/DMS.Infrastructure/Repositories/InitializeRepository.cs +++ b/DMS.Infrastructure/Repositories/InitializeRepository.cs @@ -34,7 +34,6 @@ public class InitializeRepository : IInitializeRepository public void InitializeTables() { _db.DbMaintenance.CreateDatabase(); // 创建数据库(如果不存在) - _db.CodeFirst.InitTables(); _db.CodeFirst.InitTables(); _db.CodeFirst.InitTables(); _db.CodeFirst.InitTables(); diff --git a/DMS.WPF/Configurations/nlog.config b/DMS.WPF/Configurations/nlog.config index 27ed46f..fc71cfe 100644 --- a/DMS.WPF/Configurations/nlog.config +++ b/DMS.WPF/Configurations/nlog.config @@ -2,8 +2,8 @@ + internalLogLevel="Trace" + internalLogFile="logs/internal-nlog.txt"> @@ -20,15 +20,30 @@ - - - + + - INSERT INTO dbnlog ( + CREATE TABLE IF NOT EXISTS nlog ( + ID INT AUTO_INCREMENT PRIMARY KEY, + LogTime DATETIME, + Level VARCHAR(50), + ThreadID INT, + ThreadName VARCHAR(100), + Callsite VARCHAR(300), + CallsiteLineNumber INT, + Message TEXT, + Logger VARCHAR(300), + Exception TEXT, + CallerFilePath VARCHAR(300), + CallerLineNumber INT, + CallerMember VARCHAR(100) + ); + + INSERT INTO nlog ( LogTime, Level, ThreadID,ThreadName,Callsite,CallsiteLineNumber,Message, Logger, Exception, CallerFilePath, CallerLineNumber,CallerMember ) VALUES (