|
@@ -8,6 +8,7 @@
|
|
|
// 在任何情况下,作者或版权持有人均不对任何索赔、损害或其他责任负责,无论是因合同、侵权或其他方式引起的,与软件或其使用或其他交易有关。
|
|
// 在任何情况下,作者或版权持有人均不对任何索赔、损害或其他责任负责,无论是因合同、侵权或其他方式引起的,与软件或其使用或其他交易有关。
|
|
|
|
|
|
|
|
using Nest;
|
|
using Nest;
|
|
|
|
|
+using System;
|
|
|
|
|
|
|
|
namespace Admin.NET.Core;
|
|
namespace Admin.NET.Core;
|
|
|
|
|
|
|
@@ -36,8 +37,62 @@ public class ElasticSearchLoggingWriter : IDatabaseLoggingWriter
|
|
|
|
|
|
|
|
// 不记录登录登出日志
|
|
// 不记录登录登出日志
|
|
|
if (loggingMonitor.actionName == "userInfo" || loggingMonitor.actionName == "logout")
|
|
if (loggingMonitor.actionName == "userInfo" || loggingMonitor.actionName == "logout")
|
|
|
- return;
|
|
|
|
|
-
|
|
|
|
|
|
|
+ return;
|
|
|
|
|
+ //解决日志无法写入问题
|
|
|
|
|
+ #region 处理操作日志
|
|
|
|
|
+ // 获取当前操作者
|
|
|
|
|
+ string account = "", realName = "", userId = "", tenantId = "";
|
|
|
|
|
+ if (loggingMonitor.authorizationClaims != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ foreach (var item in loggingMonitor.authorizationClaims)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (item.type == ClaimConst.Account)
|
|
|
|
|
+ account = item.value;
|
|
|
|
|
+ if (item.type == ClaimConst.RealName)
|
|
|
|
|
+ realName = item.value;
|
|
|
|
|
+ if (item.type == ClaimConst.TenantId)
|
|
|
|
|
+ tenantId = item.value;
|
|
|
|
|
+ if (item.type == ClaimConst.UserId)
|
|
|
|
|
+ userId = item.value;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ string remoteIPv4 = loggingMonitor.remoteIPv4;
|
|
|
|
|
+ (string ipLocation, double? longitude, double? latitude) = DatabaseLoggingWriter.GetIpAddress(remoteIPv4);
|
|
|
|
|
+ var client = Parser.GetDefault().Parse(loggingMonitor.userAgent.ToString());
|
|
|
|
|
+ var browser = $"{client.UA.Family} {client.UA.Major}.{client.UA.Minor} / {client.Device.Family}";
|
|
|
|
|
+ var os = $"{client.OS.Family} {client.OS.Major} {client.OS.Minor}";
|
|
|
|
|
+
|
|
|
|
|
+ SysLogOp op = new SysLogOp
|
|
|
|
|
+ {
|
|
|
|
|
+ Id = DateTime.Now.Ticks,
|
|
|
|
|
+ ControllerName = loggingMonitor.controllerName,
|
|
|
|
|
+ ActionName = loggingMonitor.actionTypeName,
|
|
|
|
|
+ DisplayTitle = loggingMonitor.displayTitle,
|
|
|
|
|
+ Status = loggingMonitor.returnInformation.httpStatusCode,
|
|
|
|
|
+ RemoteIp = remoteIPv4,
|
|
|
|
|
+ Location = ipLocation,
|
|
|
|
|
+ Longitude = longitude,
|
|
|
|
|
+ Latitude = latitude,
|
|
|
|
|
+ Browser = loggingMonitor.userAgent,
|
|
|
|
|
+ Os = loggingMonitor.osDescription + " " + loggingMonitor.osArchitecture,
|
|
|
|
|
+ Elapsed = loggingMonitor.timeOperationElapsedMilliseconds,
|
|
|
|
|
+ LogDateTime = logMsg.LogDateTime,
|
|
|
|
|
+ Account = account,
|
|
|
|
|
+ RealName = realName,
|
|
|
|
|
+ HttpMethod = loggingMonitor.httpMethod,
|
|
|
|
|
+ RequestUrl = loggingMonitor.requestUrl,
|
|
|
|
|
+ RequestParam = (loggingMonitor.parameters == null || loggingMonitor.parameters.Count == 0) ? null : JSON.Serialize(loggingMonitor.parameters[0].value),
|
|
|
|
|
+ ReturnResult = JSON.Serialize(loggingMonitor.returnInformation),
|
|
|
|
|
+ EventId = logMsg.EventId.Id,
|
|
|
|
|
+ ThreadId = logMsg.ThreadId,
|
|
|
|
|
+ TraceId = logMsg.TraceId,
|
|
|
|
|
+ Exception = (loggingMonitor.exception == null) ? null : JSON.Serialize(loggingMonitor.exception),
|
|
|
|
|
+ Message = logMsg.Message,
|
|
|
|
|
+ CreateUserId = string.IsNullOrWhiteSpace(userId) ? 0 : long.Parse(userId),
|
|
|
|
|
+ TenantId = string.IsNullOrWhiteSpace(tenantId) ? 0 : long.Parse(tenantId)
|
|
|
|
|
+ };
|
|
|
|
|
+ #endregion
|
|
|
await _esClient.IndexDocumentAsync(jsonStr);
|
|
await _esClient.IndexDocumentAsync(jsonStr);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|