-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.cs
More file actions
41 lines (36 loc) · 1.13 KB
/
Logger.cs
File metadata and controls
41 lines (36 loc) · 1.13 KB
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
// I:\Clear-Cache-Icons\ClearCacheIcons\Logger.cs
using System;
using System.Drawing;
using System.Windows.Forms;
namespace ClearCacheIcons
{
public static class Logger
{
private static RichTextBox? _logTextBox; // Hacerlo anulable
public static void Initialize(RichTextBox logTextBox)
{
_logTextBox = logTextBox;
}
public static void Log(string message, bool isError = false)
{
if (_logTextBox == null) return; // Comprobación de nulidad
if (_logTextBox.InvokeRequired)
{
_logTextBox.Invoke(new Action(() => Log(message, isError)));
return;
}
_logTextBox.SelectionColor = Color.White;
_logTextBox.AppendText($"[{DateTime.Now:HH:mm:ss}] ");
if (isError)
{
_logTextBox.SelectionColor = Color.Red;
}
else
{
_logTextBox.SelectionColor = Color.White;
}
_logTextBox.AppendText(message + Environment.NewLine);
_logTextBox.ScrollToCaret();
}
}
}