1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- 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 void Info(string msg)
- {
- var pro = Process.GetCurrentProcess();
- _ = HttpHelper.PostRequestAsync<List<LogModulesResDto>>(BaseUrl + "Log/Add", new LogInfoDto()
- {
- LogTime = DateTime.Now,
- LogType = EnumLogTypeDto.Info,
- Module = pro.ProcessName,
- Msg = msg
- });
- Serilog.Log.Information(msg);
- Serilog.Log.Information("MainWindowTitle=" + pro.MainWindowTitle);
- Serilog.Log.Information("ModuleName=" + pro.MainModule.ModuleName);
- Serilog.Log.Information("FileName=" + pro.MainModule.FileName);
- Logger?.Invoke(new LogInfo() { LogType = EnumLogType.Info, Msg = msg });
- }
- public static void Warning(string msg, Exception ex = null)
- {
- _ = HttpHelper.PostRequestAsync<List<LogModulesResDto>>(BaseUrl + "Log/Add", new LogInfoDto()
- {
- LogTime = DateTime.Now,
- LogType = EnumLogTypeDto.Warning,
- Module = Process.GetCurrentProcess().ProcessName,
- Msg = msg
- });
- Serilog.Log.Warning(ex, msg);
- Logger?.Invoke(new LogInfo() { LogType = EnumLogType.Warning, Msg = msg });
- }
- public static void 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;
- }
- _ = HttpHelper.PostRequestAsync<List<LogModulesResDto>>(BaseUrl + "Log/Add", new LogInfoDto()
- {
- LogTime = DateTime.Now,
- LogType = EnumLogTypeDto.Error,
- Module = Process.GetCurrentProcess().ProcessName,
- Msg = msg
- });
- Serilog.Log.Error(ex, msg);
- Logger?.Invoke(new LogInfo() { LogType = EnumLogType.Error, Msg = msg });
- }
- }
- }
|