65 lines
2.0 KiB
C#
65 lines
2.0 KiB
C#
|
|
using Models;
|
|||
|
|
using Models.ModelItems;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using System.Web;
|
|||
|
|
|
|||
|
|
namespace Services.Manager
|
|||
|
|
{
|
|||
|
|
public class DbLogServer
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 写日志
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="uid">操作者</param>
|
|||
|
|
/// <param name="content">内容</param>
|
|||
|
|
/// <param name="type">0 新增 1 更新 2 删除</param>
|
|||
|
|
public static void WriteDbLog(string content, int type = 0, DbLog logs = null)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
//从Session拷贝一个模板过来
|
|||
|
|
DbLog log = new DbLog();
|
|||
|
|
log = logs != null ? logs : HttpContext.Current.Session["log"] as DbLog;
|
|||
|
|
if(logs != null)
|
|||
|
|
{
|
|||
|
|
log = logs;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
DbLog tmpSessionLog = HttpContext.Current.Session["log"] as DbLog;
|
|||
|
|
if(tmpSessionLog != null)
|
|||
|
|
{
|
|||
|
|
log = tmpSessionLog;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
log.location = "";
|
|||
|
|
log.Ip = "";
|
|||
|
|
log.Client = "";
|
|||
|
|
log.Uid = "";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
//除了content, type, 其他的全部用模板的值
|
|||
|
|
DbLog dlog = new DbLog
|
|||
|
|
{
|
|||
|
|
location = log.location,
|
|||
|
|
Ip = log.Ip,
|
|||
|
|
Client = log.Client,
|
|||
|
|
CreateTime = DateTime.Now,
|
|||
|
|
Uid = log.Uid,
|
|||
|
|
Type = type,
|
|||
|
|
Content = content
|
|||
|
|
};
|
|||
|
|
SqlSugarBase.Db.Insertable(dlog).ExecuteCommand();
|
|||
|
|
}
|
|||
|
|
catch (Exception EX)
|
|||
|
|
{
|
|||
|
|
LogHelp.WriteExceptionLog(EX);
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|