-
Notifications
You must be signed in to change notification settings - Fork 1
/
ServerLogs.cs
75 lines (66 loc) · 2.24 KB
/
ServerLogs.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using NLog;
namespace AudiobookshelfTray
{
public partial class ServerLogs : Form
{
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
public ServerLogs()
{
InitializeComponent();
// handle context menu item clicks
selectAllToolStripMenuItem.Click += new EventHandler(SelectAllToolStripMenuItem_Click);
copySelectedToolStripMenuItem.Click += new EventHandler(CopySelectedToolStripMenuItem_Click);
}
public void SetLogs(List<string> logLines)
{
_logger.Debug("Setting Logs " + logLines.Count);
string[] linesArray = [.. logLines];
if (linesArray != null && linesArray.Length > 0)
{
logsListBox.Invoke((MethodInvoker)delegate
{
logsListBox.Items.AddRange(linesArray);
logsListBox.SelectedIndex = logsListBox.Items.Count - 1;
});
}
else
{
_logger.Error("Error: Invalid logLines");
}
}
public void AddLogLine(string line)
{
if (line == "" || line == null) return;
logsListBox.Invoke((MethodInvoker)delegate
{
logsListBox.Items.Add(line);
logsListBox.SelectedIndex = logsListBox.Items.Count - 1;
});
}
private void CopySelectedToolStripMenuItem_Click(object sender, EventArgs e)
{
// copy selected items to clipboard
StringBuilder sb = new();
foreach (string s in logsListBox.SelectedItems)
{
sb.AppendLine(s);
}
Clipboard.SetText(sb.ToString());
}
private void SelectAllToolStripMenuItem_Click(object sender, EventArgs e)
{
// select all items in the listbox
logsListBox.BeginUpdate();
for (int i = 0; i < logsListBox.Items.Count; i++)
{
logsListBox.SetSelected(i, true);
}
logsListBox.EndUpdate();
}
}
}