-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathGuiLogger.cs
More file actions
54 lines (42 loc) · 898 Bytes
/
GuiLogger.cs
File metadata and controls
54 lines (42 loc) · 898 Bytes
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
using System.Diagnostics.Contracts;
using System.Windows.Forms;
using ReClassNET.Forms;
using System;
namespace ReClassNET.Logger
{
/// <summary>A logger which displays messages in a form.</summary>
public class GuiLogger : BaseLogger
{
private readonly LogForm form;
public LogLevel Level { get; set; } = LogLevel.Warning;
public GuiLogger()
{
form = new LogForm();
form.FormClosing += delegate (object sender, FormClosingEventArgs e)
{
form.Clear();
form.Hide();
e.Cancel = true;
};
NewLogEntry += OnNewLogEntry;
}
private void OnNewLogEntry(LogLevel level, string message, Exception ex)
{
Contract.Requires(message != null);
if (level < Level)
{
return;
}
ShowForm();
form.Add(level, message, ex);
}
public void ShowForm()
{
if (!form.Visible)
{
form.Show();
form.BringToFront();
}
}
}
}