|
|
@ -1,17 +1,14 @@ |
|
|
|
using Tiobon.Core.Common.Helper; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using Newtonsoft.Json; |
|
|
|
|
|
|
|
using System; |
|
|
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
|
|
using System.IO; |
|
|
|
|
|
|
|
using System.Linq; |
|
|
|
|
|
|
|
using System.Text; |
|
|
|
using System.Text; |
|
|
|
using System.Threading; |
|
|
|
|
|
|
|
using Serilog; |
|
|
|
using Serilog; |
|
|
|
|
|
|
|
using Tiobon.Core.Common.Helper; |
|
|
|
|
|
|
|
using Tiobon.Core.Model; |
|
|
|
|
|
|
|
using Tiobon.Core.Common.DB.Dapper; |
|
|
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.Common.LogHelper |
|
|
|
namespace Tiobon.Core.Common.LogHelper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class LogLock |
|
|
|
{ |
|
|
|
{ |
|
|
|
public class LogLock |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
static ReaderWriterLockSlim LogWriteLock = new ReaderWriterLockSlim(); |
|
|
|
static ReaderWriterLockSlim LogWriteLock = new ReaderWriterLockSlim(); |
|
|
|
static int WritedCount = 0; |
|
|
|
static int WritedCount = 0; |
|
|
|
static int FailedCount = 0; |
|
|
|
static int FailedCount = 0; |
|
|
@ -86,7 +83,7 @@ namespace Tiobon.Core.Common.LogHelper |
|
|
|
// 因进入与退出写入模式应在同一个try finally语句块内,所以在请求进入写入模式之前不能触发异常,否则释放次数大于请求次数将会触发异常 |
|
|
|
// 因进入与退出写入模式应在同一个try finally语句块内,所以在请求进入写入模式之前不能触发异常,否则释放次数大于请求次数将会触发异常 |
|
|
|
LogWriteLock.EnterWriteLock(); |
|
|
|
LogWriteLock.EnterWriteLock(); |
|
|
|
|
|
|
|
|
|
|
|
var folderPath = Path.Combine(_contentRoot, "Log"); |
|
|
|
var folderPath = Path.Combine(_contentRoot, $@"Logs\\{DateTime.Now.ToString("yyyyMMdd")}"); |
|
|
|
if (!Directory.Exists(folderPath)) |
|
|
|
if (!Directory.Exists(folderPath)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Directory.CreateDirectory(folderPath); |
|
|
|
Directory.CreateDirectory(folderPath); |
|
|
@ -207,6 +204,23 @@ namespace Tiobon.Core.Common.LogHelper |
|
|
|
case "RecordAccessLogs": |
|
|
|
case "RecordAccessLogs": |
|
|
|
//TODO 是否需要Debug输出? |
|
|
|
//TODO 是否需要Debug输出? |
|
|
|
Log.Information(logContent); |
|
|
|
Log.Information(logContent); |
|
|
|
|
|
|
|
Task.Factory.StartNew(() => |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var requestInfo = JsonHelper.JsonToObj<UserAccessModel>(logContent); |
|
|
|
|
|
|
|
if (requestInfo != null && requestInfo.API != "/api/file/upload") |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
DbInsert di = new DbInsert("Ghre_ApiLog"); |
|
|
|
|
|
|
|
di.Values("UserId", requestInfo.User); |
|
|
|
|
|
|
|
di.Values("IP", requestInfo.IP); |
|
|
|
|
|
|
|
di.Values("Path", requestInfo.API); |
|
|
|
|
|
|
|
di.Values("Method", requestInfo.RequestMethod); |
|
|
|
|
|
|
|
di.Values("RequestData", requestInfo.RequestData); |
|
|
|
|
|
|
|
di.Values("BeginTime", requestInfo.BeginTime); |
|
|
|
|
|
|
|
di.Values("OPTime", requestInfo.OPTime.Replace("ms", null)); |
|
|
|
|
|
|
|
di.Values("Agent", requestInfo.Agent); |
|
|
|
|
|
|
|
DbAccess.ExcuteNonQuery(di.GetSql()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case "SqlLog": |
|
|
|
case "SqlLog": |
|
|
|
Log.Information(logContent); |
|
|
|
Log.Information(logContent); |
|
|
@ -592,10 +606,10 @@ namespace Tiobon.Core.Common.LogHelper |
|
|
|
rows = apiDates, |
|
|
|
rows = apiDates, |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public enum ReadType |
|
|
|
public enum ReadType |
|
|
|
{ |
|
|
|
{ |
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// 精确查找一个 |
|
|
|
/// 精确查找一个 |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
@ -610,5 +624,4 @@ namespace Tiobon.Core.Common.LogHelper |
|
|
|
/// 指定前缀,最新一个文件 |
|
|
|
/// 指定前缀,最新一个文件 |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
PrefixLatest |
|
|
|
PrefixLatest |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |