PageLogManage.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using HZY.Framework.DependencyInjection;
  12. using Sunny.UI;
  13. namespace Scada.Page
  14. {
  15. public partial class PageLogManage : UIPage, ISingletonSelfDependency
  16. {
  17. public PageLogManage()
  18. {
  19. InitializeComponent();
  20. InitCbData();
  21. }
  22. private void InitCbData()
  23. {
  24. string logpath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs");
  25. if (!Directory.Exists(logpath))
  26. {
  27. Directory.CreateDirectory(logpath);
  28. }
  29. string[] dirNames = Directory.GetDirectories(logpath);
  30. dirNames.ForEach(dir =>
  31. {
  32. this.cb_Date.Items.Add(Path.GetFileName(dir));
  33. });
  34. }
  35. private void PageLogManage_Load(object sender, EventArgs e)
  36. {
  37. }
  38. private void PageLogManage_Initialize(object sender, EventArgs e)
  39. {
  40. }
  41. private void cb_Date_SelectedIndexChanged(object sender, EventArgs e)
  42. {
  43. string logPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs", this.cb_Date.SelectedItem.ToString());
  44. string[] dirNames = Directory.GetDirectories(logPath);
  45. this.cb_LogLev.Items.Clear();
  46. dirNames.ForEach(x =>
  47. {
  48. this.cb_LogLev.Items.Add(Path.GetFileName(x));
  49. });
  50. }
  51. private void cb_LogLev_SelectedIndexChanged(object sender, EventArgs e)
  52. {
  53. if (this.cb_Date.SelectedItem == null)
  54. {
  55. UIMessageTip.ShowError("请先选择日期");
  56. return;
  57. }
  58. if (this.cb_LogLev.SelectedItem == null)
  59. {
  60. UIMessageTip.ShowError("请先选择日志级别");
  61. return;
  62. }
  63. string logPath = Path.Combine(Application.StartupPath, "Logs", cb_Date.SelectedItem.ToString(), cb_LogLev.SelectedItem.ToString());
  64. this.lb_Files.Items.Clear();
  65. string[] fileNames = Directory.GetFiles(logPath, "*.log");
  66. fileNames.OrderBy(x => x).ToList().ForEach(x =>
  67. {
  68. this.lb_Files.Items.Add(Path.GetFileName(x));
  69. });
  70. }
  71. private async void lb_Files_SelectedIndexChanged(object sender, EventArgs e)
  72. {
  73. if (this.cb_Date.SelectedItem == null)
  74. {
  75. UIMessageTip.ShowError("请先选择日期");
  76. return;
  77. }
  78. if (this.cb_LogLev.SelectedItem == null)
  79. {
  80. UIMessageTip.ShowError("请先选择日志级别");
  81. return;
  82. }
  83. if (this.lb_Files.SelectedItem == null)
  84. {
  85. UIMessageTip.ShowError("请先选择日志文件");
  86. return;
  87. }
  88. try
  89. {
  90. string logPath = Path.Combine(Application.StartupPath, "Logs", cb_Date.SelectedItem.ToString()
  91. , cb_LogLev.SelectedItem.ToString(), lb_Files.SelectedItem.ToString());
  92. string content = string.Empty;
  93. this.txt_ShowLog.Text = "";
  94. using (StreamReader sr = new StreamReader(logPath, Encoding.UTF8))
  95. {
  96. content = await sr.ReadToEndAsync();
  97. }
  98. this.txt_ShowLog.Text = content;
  99. }
  100. catch (Exception ex)
  101. {
  102. LogExtension.ShowMessage(ex.Message, Microsoft.Extensions.Logging.LogLevel.Error);
  103. }
  104. }
  105. private void btn_OpenDire_Click(object sender, EventArgs e)
  106. {
  107. string logPath = Path.Combine(Application.StartupPath, "Logs");
  108. ProcessStartInfo startInfo = new ProcessStartInfo()
  109. {
  110. FileName = logPath,
  111. UseShellExecute = true,
  112. };
  113. Process process = new Process
  114. {
  115. StartInfo = startInfo
  116. };
  117. process.Start();
  118. }
  119. private void btn_ShowToDgv_Click(object sender, EventArgs e)
  120. {
  121. }
  122. }
  123. }