|
|
using LifePayment.Application.Contracts;
|
using LifePayment.Domain;
|
using LifePayment.Domain.Shared;
|
using Microsoft.AspNetCore.Http;
|
using Microsoft.EntityFrameworkCore;
|
using Microsoft.Extensions.Logging;
|
using System;
|
using System.Threading.Tasks;
|
using Volo.Abp.Application.Services;
|
using Volo.Abp.Domain.Repositories;
|
|
namespace LifePayment.Application
|
{
|
public class LogService : ApplicationService, ILogService
|
{
|
private readonly ILogger<LogService> logger;
|
private readonly IHttpContextAccessor httpContextAccessor;
|
private readonly IRepository<LogFrontRecord, Guid> logFrontRepository;
|
|
public LogService(
|
ILogger<LogService> logger,
|
IHttpContextAccessor httpContextAccessor,
|
IRepository<LogFrontRecord, Guid> logFrontRepository)
|
{
|
this.logger = logger;
|
this.httpContextAccessor = httpContextAccessor;
|
this.logFrontRepository = logFrontRepository;
|
}
|
|
/// <summary>
|
/// 记录前端日志
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
public async Task LogFront(LogFrontInput input)
|
{
|
var log = new LogFrontRecord();
|
ObjectMapper.Map(input, log);
|
if (log.UserId == null)
|
{
|
log.UserId = CurrentUser?.Id;
|
}
|
log.IpAddress = httpContextAccessor.HttpContext?.Connection?.RemoteIpAddress?.ToString();
|
logger.LogInformation($"前端日志:{log.IpAddress}-{log.UserId}-{log.Url}-{log.RequestTime}-{log.Message}");
|
|
//await logFrontRepository.InsertAsync(log);
|
}
|
}
|
}
|