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
{
///
/// 日志处理
///
public partial class LoggerApp
{
///
/// 记录文本日志
/// ye m
/// 参数
/// 异常
/// 类型
/// 程序名称
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);
}
///
/// 插入日志
///
///
///
public void InsertErrorLog(string msg, int type = 1)
{
LogFactory.InsertErrorLog(msg, type);
}
///
/// 增加通知日志
///
///
///
public async Task 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(data).ExecuteReturnIdentityAsync();
return id;
}
}
}
}