diff --git a/Bootstrap.Admin/Controllers/Api/LogsController.cs b/Bootstrap.Admin/Controllers/Api/LogsController.cs
index 2c4d157e..ba6cf9c5 100644
--- a/Bootstrap.Admin/Controllers/Api/LogsController.cs
+++ b/Bootstrap.Admin/Controllers/Api/LogsController.cs
@@ -1,5 +1,6 @@
using Bootstrap.Admin.Query;
using Bootstrap.DataAccess;
+using Longbow.Web;
using Longbow.Web.Mvc;
using Microsoft.AspNetCore.Mvc;
using System.Net;
@@ -27,14 +28,19 @@ namespace Bootstrap.Admin.Controllers.Api
///
///
///
+ ///
///
///
[HttpPost]
- public bool Post([FromBody]Log value)
+ public bool Post([FromServices]IOnlineUsers onlineUserSvr, [FromBody]Log value)
{
- value.ClientAgent = Request.Headers["User-Agent"];
- value.ClientIp = (HttpContext.Connection.RemoteIpAddress ?? IPAddress.IPv6Loopback).ToString();
+ var agent = new UserAgent(Request.Headers["User-Agent"]);
+ value.Ip = HttpContext.Connection.RemoteIpAddress?.ToString();
+ value.Browser = $"{agent.Browser.Name} {agent.Browser.Version}";
+ value.OS = $"{agent.OS.Name} {agent.OS.Version}";
+ value.City = onlineUserSvr.RetrieveLocaleByIp(value.Ip);
value.UserName = User.Identity.Name;
+ if (string.IsNullOrEmpty(value.Ip)) value.Ip = IPAddress.IPv6Loopback.ToString();
return LogHelper.Save(value);
}
}
diff --git a/Bootstrap.Admin/Query/QueryLogOption.cs b/Bootstrap.Admin/Query/QueryLogOption.cs
index 926c7775..6443186d 100644
--- a/Bootstrap.Admin/Query/QueryLogOption.cs
+++ b/Bootstrap.Admin/Query/QueryLogOption.cs
@@ -57,7 +57,7 @@ namespace Bootstrap.Admin.Query
data = Order == "asc" ? data.OrderBy(t => t.LogTime) : data.OrderByDescending(t => t.LogTime);
break;
case "ClientIp":
- data = Order == "asc" ? data.OrderBy(t => t.ClientIp) : data.OrderByDescending(t => t.ClientIp);
+ data = Order == "asc" ? data.OrderBy(t => t.Ip) : data.OrderByDescending(t => t.Ip);
break;
case "RequestUrl":
data = Order == "asc" ? data.OrderBy(t => t.RequestUrl) : data.OrderByDescending(t => t.RequestUrl);
diff --git a/Bootstrap.Admin/wwwroot/js/logs.js b/Bootstrap.Admin/wwwroot/js/logs.js
index 2e8e766a..eee89034 100644
--- a/Bootstrap.Admin/wwwroot/js/logs.js
+++ b/Bootstrap.Admin/wwwroot/js/logs.js
@@ -10,9 +10,11 @@
{ title: "操作类型", field: "CRUD", sortable: true },
{ title: "用户名称", field: "UserName", sortable: true },
{ title: "操作时间", field: "LogTime", sortable: true },
- { title: "操作IP", field: "ClientIp", sortable: true },
- { title: "Url", field: "RequestUrl", sortable: true },
- { title: "备注", field: "ClientAgent", sortable: false }
+ { title: "登录主机", field: "Ip", sortable: true },
+ { title: "操作地点", field: "City", sortable: true },
+ { title: "浏览器", field: "Browser", sortable: true },
+ { title: "操作系统", field: "OS", sortable: true },
+ { title: "Url", field: "RequestUrl", sortable: true }
]
});
});
\ No newline at end of file
diff --git a/Bootstrap.DataAccess/Log.cs b/Bootstrap.DataAccess/Log.cs
index 36b7f18d..7a274e28 100644
--- a/Bootstrap.DataAccess/Log.cs
+++ b/Bootstrap.DataAccess/Log.cs
@@ -33,12 +33,22 @@ namespace Bootstrap.DataAccess
///
/// 获得/设置 客户端IP
///
- public string ClientIp { get; set; }
+ public string Ip { get; set; }
///
- /// 获取/设置 客户端信息
+ ///
///
- public string ClientAgent { get; set; }
+ public string City { get; set; }
+
+ ///
+ ///
+ ///
+ public string Browser { get; set; }
+
+ ///
+ ///
+ ///
+ public string OS { get; set; }
///
/// 获取/设置 请求网址
diff --git a/UnitTest/Bootstrap.Admin/Api/LogsTest.cs b/UnitTest/Bootstrap.Admin/Api/LogsTest.cs
index a1def8fd..db46c3e6 100644
--- a/UnitTest/Bootstrap.Admin/Api/LogsTest.cs
+++ b/UnitTest/Bootstrap.Admin/Api/LogsTest.cs
@@ -1,5 +1,6 @@
using Bootstrap.DataAccess;
using Longbow.Web.Mvc;
+using System;
using Xunit;
namespace Bootstrap.Admin.Api
@@ -11,7 +12,7 @@ namespace Bootstrap.Admin.Api
[Fact]
public async void Get_Ok()
{
- var log = new Log() { CRUD = "UnitTest", ClientAgent = "UnitTest", ClientIp = "::1", RequestUrl = "~/UnitTest", UserName = "UnitTest" };
+ var log = new Log() { CRUD = "UnitTest", Browser = "UnitTest", OS = "UnitTest", City = "本地连接", Ip = "::1", RequestUrl = "~/UnitTest", UserName = "UnitTest", LogTime = DateTime.Now };
log.Save(log);
// 菜单 系统菜单 系统使用条件
diff --git a/UnitTest/Bootstrap.DataAccess/LogsTest.cs b/UnitTest/Bootstrap.DataAccess/LogsTest.cs
index b1499a38..0ec9f7cb 100644
--- a/UnitTest/Bootstrap.DataAccess/LogsTest.cs
+++ b/UnitTest/Bootstrap.DataAccess/LogsTest.cs
@@ -3,7 +3,7 @@
namespace Bootstrap.DataAccess
{
[Collection("SQLServerContext")]
- public class LogsTest
+ public class LogsTest
{
[Fact]
public void Save_Ok()
@@ -11,8 +11,10 @@ namespace Bootstrap.DataAccess
var log = new Log()
{
UserName = "UnitTest",
- ClientAgent = "UnitTest-Agent",
- ClientIp = "::",
+ Browser = "UnitTest",
+ City = "本地连接",
+ OS = "UnitTest",
+ Ip = "::",
CRUD = "UnitTest",
RequestUrl = "~/Home/Index"
};
@@ -25,8 +27,10 @@ namespace Bootstrap.DataAccess
var log = new Log()
{
UserName = "UnitTest",
- ClientAgent = "UnitTest-Agent",
- ClientIp = "::",
+ Browser = "UnitTest",
+ City = "本地连接",
+ OS = "UnitTest",
+ Ip = "::",
CRUD = "UnitTest",
RequestUrl = "~/Home/Index"
};