12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using XdCxRhDW.Dto;
- namespace X1LeoTaskServer54
- {
- public static class LogHelper
- {
- public static Action<LogInfo> Logger;
- public static string BaseUrl;
- public static async Task Info(string msg)
- {
- var pro = Process.GetCurrentProcess();
- try
- {
- await HttpHelper.PostRequestAsync<List<LogModulesResDto>>(BaseUrl + "Log/Add", new LogInfoDto()
- {
- LogTime = DateTime.Now,
- LogType = EnumLogTypeDto.Info,
- Module = pro.ProcessName,
- Msg = msg
- }, 5);
- }
- catch
- {
- }
- Serilog.Log.Information(msg);
- if (!string.IsNullOrWhiteSpace(pro.MainWindowTitle))
- Logger?.Invoke(new LogInfo() { LogType = EnumLogType.Info, Msg = msg });
- }
- public static async Task Warning(string msg, Exception ex = null)
- {
- var pro = Process.GetCurrentProcess();
- try
- {
- await HttpHelper.PostRequestAsync<List<LogModulesResDto>>(BaseUrl + "Log/Add", new LogInfoDto()
- {
- LogTime = DateTime.Now,
- LogType = EnumLogTypeDto.Info,
- Module = pro.ProcessName,
- Msg = msg
- }, 5);
- }
- catch
- {
- }
- Serilog.Log.Warning(ex, msg);
- if (!string.IsNullOrWhiteSpace(pro.MainWindowTitle))
- Logger?.Invoke(new LogInfo() { LogType = EnumLogType.Warning, Msg = msg });
- }
- 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
- {
- await HttpHelper.PostRequestAsync<List<LogModulesResDto>>(BaseUrl + "Log/Add", new LogInfoDto()
- {
- LogTime = DateTime.Now,
- LogType = EnumLogTypeDto.Info,
- Module = pro.ProcessName,
- Msg = msg
- }, 5);
- }
- catch
- {
- }
- Serilog.Log.Error(ex, msg);
- if (!string.IsNullOrWhiteSpace(pro.MainWindowTitle))
- Logger?.Invoke(new LogInfo() { LogType = EnumLogType.Error, Msg = msg });
- }
- }
- }
|