123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using Bowin.Common.Utility;
- using YLShipBuildLandMap.Entity;
- using Microsoft.AspNetCore.Http;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections.Generic;
- using System.Security.Claims;
- using System.Text;
- namespace YLShipBuildLandMap.Services.SystemSetting
- {
- public class SysLogService : Bowin.Common.Log.IDbLog
- {
- private YLShipBuildLandMapContext DbContext { get; set; }
- public SysLogService(YLShipBuildLandMapContext dbContext) {
- this.DbContext = dbContext;
- }
- public bool DbWrite(Exception ex,HttpContext httpContext)
- {
- try
- {
- SysLog log = new SysLog();
- string ip = httpContext.Connection.RemoteIpAddress.ToString();
- log.LogId = Guid.NewGuid();
- log.LogTime = DateTime.Now;
- log.ClientIp = ip;
- if (httpContext.User != null)
- {
- var roleClaim = httpContext.User.FindFirst(ClaimTypes.Name);
- log.LogUser = roleClaim != null ? roleClaim.Value : "";
- }
- log.LogTitle = httpContext.Request.Path.HasValue ? httpContext.Request.Path.Value : "";
- log.LogDescribe = "filterError";
- log.LogType = 2;
- log.LogText = JsonConvert.SerializeObject(new { ex.Message,ex.StackTrace }); ;
- this.DbContext.SysLog.Add(log);
- this.DbContext.SaveChanges();
- return true;
- }
- catch {
- return false;
- }
- }
- public bool DbWrite(JObject jobject)
- {
- try
- {
- var httpContext= HttpHelper.Current;
- SysLog log = new SysLog();
- string ip = httpContext.Connection.RemoteIpAddress.ToString();
- log.LogId = Guid.NewGuid();
- log.LogTime = DateTime.Now;
- log.ClientIp = ip;
-
-
- if (httpContext.User != null)
- {
- var roleClaim = httpContext.User.FindFirst(ClaimTypes.Name);
- log.LogUser = roleClaim != null ? roleClaim.Value : "";
- }
- log.LogTitle = httpContext.Request.Path.HasValue ? httpContext.Request.Path.Value : "";
- log.LogDescribe = "request";
- log.LogType = 3;
- log.LogText = JsonConvert.SerializeObject(jobject);
- this.DbContext.SysLog.Add(log);
- this.DbContext.SaveChanges();
- return true;
- }
- catch
- {
- return false;
- }
- }
- }
- }
|