添加了NLog日志,并且配置了写入数据库,修改了Notification通知不使用依赖注入,而是使用Message的方式
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace PMSWPF.Data.Entities;
|
||||
|
||||
[SugarTable("Mqtt")]
|
||||
|
||||
public class DbMqtt
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]//数据库是自增才配自增
|
||||
|
||||
32
Data/Entities/DbNlog.cs
Normal file
32
Data/Entities/DbNlog.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace PMSWPF.Data.Entities;
|
||||
|
||||
[SugarTable("nlog")]
|
||||
public class DbNlog
|
||||
{
|
||||
// INSERT INTO [dbo].[NLog] (
|
||||
// [Application], [Logged], [Level], [ThreadID],[Message],
|
||||
// [Logger], [Callsite], [Exception], [Url], [Action], [User]
|
||||
// ) VALUES (
|
||||
// @Application, @Logged, @Level,@ThreadID, @Message,
|
||||
// @Logger, @Callsite, @Exception, @Url, @Action, @User
|
||||
// )
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]//数据库是自增才配自增
|
||||
public int Id { get; set; }
|
||||
public DateTime LogTime { get; set; }
|
||||
public string Level { get; set; }
|
||||
public int ThreadID { get; set; }
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string ThreadName { get; set; }
|
||||
public string Logger { get; set; }
|
||||
public string Callsite { get; set; }
|
||||
public int CallsiteLineNumber { get; set; }
|
||||
public string Message { get; set; }
|
||||
[SugarColumn(IsNullable = true,ColumnDataType = "text")]
|
||||
public string Exception { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -9,13 +9,23 @@ public class BaseRepositories
|
||||
|
||||
public BaseRepositories()
|
||||
{
|
||||
_db = DbContext.GetInstance();
|
||||
_db.DbMaintenance.CreateDatabase();
|
||||
CheckDbTables();
|
||||
try
|
||||
{
|
||||
_db = DbContext.GetInstance();
|
||||
// _db.DbMaintenance.CreateDatabase();
|
||||
// CheckDbTables();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckDbTables()
|
||||
{
|
||||
if(!_db.DbMaintenance.IsAnyTable<DbNlog>())
|
||||
_db.CodeFirst.InitTables<DbNlog>();
|
||||
if(!_db.DbMaintenance.IsAnyTable<DbDevice>())
|
||||
_db.CodeFirst.InitTables<DbDevice>();
|
||||
if(!_db.DbMaintenance.IsAnyTable<DbVariableTable>())
|
||||
|
||||
Reference in New Issue
Block a user