12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using XdCxRhDW.Dto;
- using XdCxRhDW.Entity;
- using XdCxRhDW.Repostory;
- namespace XdCxRhDW.App
- {
- public static class LogHelper
- {
- public static async Task Info(string msg)
- {
- var pro = Process.GetCurrentProcess();
- try
- {
- using (MySqlContext db = new MySqlContext())
- {
- LogRes res = new LogRes()
- {
- LogTime = DateTime.Now,
- Module = pro.ProcessName,
- LogType = EnumLogType.Info,
- Msg = msg,
- };
- db.LogRes.Add(res);
- await db.SaveChangesAsync();
- }
- }
- catch (Exception ex)
- {
- XdCxRhDW.Framework.LogHelper.Error("日志信息写入异常", ex);
- }
- XdCxRhDW.Framework.LogHelper.Info(msg);
- }
- public static async Task Warning(string msg, Exception ex = null)
- {
- var pro = Process.GetCurrentProcess();
- try
- {
- using (MySqlContext db = new MySqlContext())
- {
- LogRes res = new LogRes()
- {
- LogTime = DateTime.Now,
- Module = pro.ProcessName,
- LogType = EnumLogType.Warning,
- Msg = msg,
- };
- db.LogRes.Add(res);
- await db.SaveChangesAsync();
- }
- }
- catch (Exception arg)
- {
- XdCxRhDW.Framework.LogHelper.Error("日志信息写入异常", arg);
- }
- XdCxRhDW.Framework.LogHelper.Warning(msg, ex);
- }
- public static async Task Error(string msg, Exception ex = null)
- {
- if (ex != null && ex.GetType() == typeof(AggregateException))
- {
- var iex = (ex as AggregateException).InnerExceptions.FirstOrDefault();
- if (iex != null)
- ex = iex;
- }
- var pro = Process.GetCurrentProcess();
- try
- {
- using (MySqlContext db = new MySqlContext())
- {
- LogRes res = new LogRes()
- {
- LogTime = DateTime.Now,
- Module = pro.ProcessName,
- LogType = EnumLogType.Error,
- Msg = msg,
- };
- db.LogRes.Add(res);
- await db.SaveChangesAsync();
- }
- }
- catch (Exception arg)
- {
- XdCxRhDW.Framework.LogHelper.Error("日志信息写入异常", arg);
- }
- XdCxRhDW.Framework.LogHelper.Error(msg, ex);
- }
- }
- }
|