74 lines
2.4 KiB
C#
74 lines
2.4 KiB
C#
using Nirvana.Common;
|
|
using Nirvana.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using YBDevice.Entity;
|
|
|
|
namespace YBDevice.NApi.DBServices
|
|
{
|
|
/// <summary>
|
|
/// 日志处理
|
|
/// </summary>
|
|
public partial class LoggerApp
|
|
{
|
|
/// <summary>
|
|
/// 记录文本日志
|
|
/// </summary>ye m
|
|
/// <param name="param">参数</param>
|
|
/// <param name="ex">异常</param>
|
|
/// <param name="type">类型</param>
|
|
/// <param name="program">程序名称</param>
|
|
public void InsertErrorLog(Exception ex, string param = "", string program = "", int type = 1)
|
|
{
|
|
var msg = $"ex:{ex.Message},source:{ex.Source}\r\nstack:{ex.StackTrace}";
|
|
if (ex.InnerException != null)
|
|
{
|
|
msg = $"{msg}\r\nInnerException.Message:{ex.InnerException.Message},InnerException.Source:{ex.InnerException.Source}\r\nInnerException.StackTrace:{ex.InnerException.StackTrace}";
|
|
}
|
|
if (!string.IsNullOrEmpty(param))
|
|
{
|
|
msg = $"参数:{param}\r\n{msg}";
|
|
}
|
|
if (!string.IsNullOrEmpty(program))
|
|
{
|
|
msg = $"{program}:{msg}";
|
|
}
|
|
InsertErrorLog(msg, type);
|
|
}
|
|
/// <summary>
|
|
/// 插入日志
|
|
/// </summary>
|
|
/// <param name="msg"></param>
|
|
/// <param name="type"></param>
|
|
public void InsertErrorLog(string msg, int type = 1)
|
|
{
|
|
LogFactory.InsertErrorLog(msg, type);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 增加通知日志
|
|
/// </summary>
|
|
/// <param name="log"></param>
|
|
/// <returns></returns>
|
|
public async Task<int> InsertNoticeLogAsync(YB_NoticeLog log)
|
|
{
|
|
using (var dbClient = ReadDbContext.GetInstance())
|
|
{
|
|
var data = new YB_NoticeLog
|
|
{
|
|
Ip = Net.Ip,
|
|
CreateTime = DateTime.Now,
|
|
FromInfo = log.FromInfo.ToStr(),
|
|
Info = log.Info.ToStr(),
|
|
UA = log.UA.ToStr(),
|
|
UserInfo = log.UserInfo.ToStr()
|
|
};
|
|
int id = await dbClient.Insertable<YB_NoticeLog>(data).ExecuteReturnIdentityAsync();
|
|
return id;
|
|
}
|
|
}
|
|
}
|
|
}
|