仓储-build

This commit is contained in:
tongfei
2023-10-18 10:56:19 +08:00
parent 05ee79a04f
commit b477662e67
10 changed files with 825 additions and 5 deletions

View File

@@ -0,0 +1,39 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace WMS.Web.Repositories.Configuration.Log
{
public class EFCoreLogger : ILogger
{
private readonly string categoryName;
public EFCoreLogger(string categoryName) => this.categoryName = categoryName;
public bool IsEnabled(LogLevel logLevel) => true;
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
if (categoryName == "Microsoft.EntityFrameworkCore.Database.Command" && logLevel == LogLevel.Information)
{
var logContent = formatter(state, exception);
var str = logContent.ToLower();
if ((str.Contains("update") || str.Contains("delete") || str.Contains("insert")) &&
(str.Contains("t_sub_ppbom") || str.Contains("t_sub_ppbomentry") || str.Contains("t_sub_ppbomentry_l")
|| str.Contains("t_prd_ppbom") || str.Contains("t_prd_ppbomentry") || str.Contains("t_prd_ppbomentry_l")
|| str.Contains("t_eng_bom") || str.Contains("t_eng_bomchild")))
{
if (!Directory.Exists("D:/Logs"))
Directory.CreateDirectory("D:/Logs");
logContent = "\r\n\r\n" + DateTime.Now + "--" + logContent;
//没有文件会自动创建,有就追加
System.IO.File.AppendAllText("D:/Logs/增删改记录.txt", logContent);
}
}
}
public IDisposable BeginScope<TState>(TState state) => null;
}
}

View File

@@ -0,0 +1,13 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;
namespace WMS.Web.Repositories.Configuration.Log
{
public class EFCoreLoggerProvider : ILoggerProvider
{
public ILogger CreateLogger(string categoryName) => new EFCoreLogger(categoryName);
public void Dispose() { }
}
}