LogHelper.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace X3TaskServer54
  7. {
  8. public static class LogHelper
  9. {
  10. public static Action<LogInfo> Logger;
  11. public static void Info(string msg)
  12. {
  13. Serilog.Log.Information(msg);
  14. Logger?.Invoke(new LogInfo() { LogType = EnumLogType.Info, Msg = msg });
  15. }
  16. public static void Warning(string msg, Exception ex = null)
  17. {
  18. Serilog.Log.Warning(ex, msg);
  19. Logger?.Invoke(new LogInfo() { LogType = EnumLogType.Warning, Msg = msg });
  20. }
  21. public static void Error(string msg, Exception ex = null)
  22. {
  23. if (ex != null && ex.GetType() == typeof(AggregateException))
  24. {
  25. var iex = (ex as AggregateException).InnerExceptions.FirstOrDefault();
  26. if (iex != null)
  27. ex = iex;
  28. }
  29. Serilog.Log.Error(ex, msg);
  30. Logger?.Invoke(new LogInfo() { LogType = EnumLogType.Error, Msg = msg });
  31. }
  32. }
  33. }