feat: 增加访问日志

This commit is contained in:
Argo-Tianyi 2022-01-17 12:33:46 +08:00
parent 2a7c42071a
commit 2892a2780f
4 changed files with 98 additions and 0 deletions

View File

@ -0,0 +1,57 @@
namespace BootstrapAdmin.DataAccess.Models;
/// <summary>
///
/// </summary>
public class Trace
{
/// <summary>
///
/// </summary>
public string? Id { get; set; }
/// <summary>
///
/// </summary>
public string? UserName { get; set; }
/// <summary>
///
/// </summary>
public DateTime LogTime { get; set; }
/// <summary>
///
/// </summary>
public string? Ip { get; set; }
/// <summary>
///
/// </summary>
public string? Browser { get; set; }
/// <summary>
///
/// </summary>
public string? OS { get; set; }
/// <summary>
///
/// </summary>
public string? City { get; set; }
/// <summary>
///
/// </summary>
public string? RequestUrl { get; set; }
/// <summary>
///
/// </summary>
public string? UserAgent { get; set; }
/// <summary>
///
/// </summary>
public string? Referer { get; set; }
}

View File

@ -78,6 +78,7 @@ public static class ServiceCollectionExtensions
services.AddSingleton<INavigation, NavigationService>();
services.AddSingleton<IRole, RoleService>();
services.AddSingleton<IUser, UserService>();
services.AddSingleton<ITrace, TraceService>();
return services;
}
}

View File

@ -0,0 +1,25 @@
using BootstrapAdmin.DataAccess.Models;
using BootstrapAdmin.Web.Core;
using PetaPoco;
namespace BootstrapAdmin.DataAccess.PetaPoco.Services;
class TraceService : ITrace
{
private IDatabase Database { get; }
/// <summary>
///
/// </summary>
/// <param name="db"></param>
public TraceService(IDatabase db) => Database = db;
/// <summary>
///
/// </summary>
/// <param name="trace"></param>
public void Log(Trace trace)
{
Database.Insert(trace);
}
}

View File

@ -0,0 +1,15 @@
using BootstrapAdmin.DataAccess.Models;
namespace BootstrapAdmin.Web.Core;
/// <summary>
///
/// </summary>
public interface ITrace
{
/// <summary>
///
/// </summary>
/// <param name="trace"></param>
public void Log(Trace trace);
}