系统新增调用api接口记录至db

master
xiaochanghai 12 months ago
parent fcd6383fae
commit e19d0a5284
  1. 4
      Tiobon.Core.Common/DB/DbSql/DbInsert.cs
  2. 15
      Tiobon.Core.Common/Helper/FileHelper.cs
  3. 6
      Tiobon.Core.Common/LogHelper/LogContextStatic.cs
  4. 1007
      Tiobon.Core.Common/LogHelper/LogLock.cs
  5. 12
      Tiobon.Core.Extensions/Middlewares/RecordAccessLogsMiddleware.cs
  6. 14
      Tiobon.Core.Model/ViewModels/UserAccessModel.cs

@ -270,11 +270,11 @@ namespace Tiobon.Core.Common
//create_by //create_by
var createBy = UserContext.Current.User_Id; var createBy = UserContext.Current.User_Id;
Values("CreatedBy", createBy); Values("CreateBy", createBy);
//create_date //create_date
DateTime createDate = DateTime.Now; DateTime createDate = DateTime.Now;
Values("CreatedTime", createDate); Values("CreateTime", createDate);
//create_program //create_program
//Values("CREATED_PROGRAM", createProgram); //Values("CREATED_PROGRAM", createProgram);

@ -73,15 +73,14 @@ namespace Tiobon.Core.Common.Helper
/// <returns>可用文件名</returns> /// <returns>可用文件名</returns>
public static string GetAvailableFileWithPrefixOrderSize(string folderPath, string prefix, int size = 1 * 1024 * 1024, string ext = ".log") public static string GetAvailableFileWithPrefixOrderSize(string folderPath, string prefix, int size = 1 * 1024 * 1024, string ext = ".log")
{ {
var allFiles = new DirectoryInfo(folderPath); //var allFiles = new DirectoryInfo(folderPath);
var selectFiles = allFiles.GetFiles().Where(fi => fi.Name.ToLower().Contains(prefix.ToLower()) && fi.Extension.ToLower() == ext.ToLower() && fi.Length < size).OrderByDescending(d => d.Name).ToList(); //var selectFiles = allFiles.GetFiles().Where(fi => fi.Name.ToLower().Contains(prefix.ToLower()) && fi.Extension.ToLower() == ext.ToLower() && fi.Length < size).OrderByDescending(d => d.Name).ToList();
if (selectFiles.Count > 0)
{
return selectFiles.FirstOrDefault().FullName;
}
return Path.Combine(folderPath, $@"{prefix}_{DateTime.Now.DateToTimeStamp()}.log"); //if (selectFiles.Count > 0)
//{
// return selectFiles.FirstOrDefault().FullName;
//}
return Path.Combine(folderPath, $@"{prefix}.log");
} }
public static string GetAvailableFileNameWithPrefixOrderSize(string _contentRoot, string prefix, int size = 1 * 1024 * 1024, string ext = ".log") public static string GetAvailableFileNameWithPrefixOrderSize(string _contentRoot, string prefix, int size = 1 * 1024 * 1024, string ext = ".log")
{ {

@ -1,6 +1,4 @@
using System.IO; namespace Tiobon.Core.Common.LogHelper;
namespace Tiobon.Core.Common.LogHelper;
public class LogContextStatic public class LogContextStatic
{ {
@ -13,7 +11,7 @@ public class LogContextStatic
} }
public static readonly string BaseLogs = "Logs"; public static readonly string BaseLogs = "Logs";
public static readonly string BasePathLogs = @"Logs"; public static string BasePathLogs { get { return DateTime.Now.ToString("yyyyMMdd"); } }
public static readonly string LogSource = "LogSource"; public static readonly string LogSource = "LogSource";
public static readonly string AopSql = "AopSql"; public static readonly string AopSql = "AopSql";

File diff suppressed because it is too large Load Diff

@ -13,6 +13,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using Tiobon.Core.Model;
namespace Tiobon.Core.Extensions.Middlewares namespace Tiobon.Core.Extensions.Middlewares
{ {
@ -122,15 +123,4 @@ namespace Tiobon.Core.Extensions.Middlewares
} }
public class UserAccessModel
{
public string User { get; set; }
public string IP { get; set; }
public string API { get; set; }
public string BeginTime { get; set; }
public string OPTime { get; set; }
public string RequestMethod { get; set; }
public string RequestData { get; set; }
public string Agent { get; set; }
}
} }

@ -0,0 +1,14 @@
namespace Tiobon.Core.Model;
public class UserAccessModel
{
public string User { get; set; }
public string IP { get; set; }
public string API { get; set; }
public string BeginTime { get; set; }
public string OPTime { get; set; }
public string RequestMethod { get; set; }
public string RequestData { get; set; }
public string Agent { get; set; }
}
Loading…
Cancel
Save