123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using XdCxRhDW.Dto;
- namespace X2LeoTaskServer54
- {
- public static class LogHelper
- {
- 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);
- }
- 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.Warning,
- Module = pro.ProcessName,
- Msg = msg
- }, 5);
- }
- catch
- {
- }
- Serilog.Log.Warning(ex, 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.Error,
- Module = pro.ProcessName,
- Msg = msg
- }, 5);
- }
- catch
- {
- }
- Serilog.Log.Error(ex, msg);
- }
- }
- }
|