Program.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using Log;
  2. using System.Threading.Channels;
  3. using Universal;
  4. namespace OnlineLogViewer;
  5. internal class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. while (true)
  10. {
  11. Console.WriteLine("IP:");
  12. string? IP = Console.ReadLine();
  13. Console.WriteLine("Port:");
  14. string? _port = Console.ReadLine();
  15. Console.WriteLine("LogLevel: ");
  16. Console.WriteLine("Info = 1");
  17. Console.WriteLine("Warning = 2");
  18. Console.WriteLine("Error = 3");
  19. Console.WriteLine("Fatal = 4");
  20. Console.WriteLine("Debug = 5");
  21. string? _level = Console.ReadLine();
  22. if (string.IsNullOrEmpty(IP) || string.IsNullOrEmpty(_port))
  23. {
  24. Console.WriteLine("Error");
  25. continue;
  26. }
  27. if (!int.TryParse(_level, out int level) || !level.In(0, 1, 2, 3, 4, 5))
  28. {
  29. Console.WriteLine("Error");
  30. continue;
  31. }
  32. if (!int.TryParse(_port, out int port))
  33. {
  34. Console.WriteLine("Error");
  35. continue;
  36. }
  37. LogHub logHub = new();
  38. if (!logHub.Initialize(IP, port, "LogHub", (LogLevel)level))
  39. {
  40. Console.WriteLine("Connect failed");
  41. continue;
  42. }
  43. break;
  44. }
  45. Thread.Sleep(-1);
  46. }
  47. }