-
Notifications
You must be signed in to change notification settings - Fork 1
/
Log.cs
81 lines (69 loc) · 2.73 KB
/
Log.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
76
77
78
79
80
81
using System;
namespace ndot
{
public static class Log
{
public static event Action<string> OnLog;
static object locker = 0;
public static void LogMsg(string text, bool newline = false, bool timestamp = false)
{
//lock (locker)
{
var msg = $"{(timestamp ? $"[{DateTime.Now}]: " : "")}{text}{(newline ? "\n" : "")}";
Console.Write(msg);
OnLog?.Invoke(msg);
}
}
#pragma warning disable CS1066
static void LogMsg(string text, System.Drawing.Color c, bool newline = false, bool timestamp = false)
{
var msg = $"{(timestamp ? $"[{DateTime.Now}]: " : "")}{text}{(newline ? '\n' : ' ')}";
Console.Write(msg);
OnLog?.Invoke(msg);
}
public static void LogMsg(string text, ConsoleColor c, ConsoleColor b = ConsoleColor.Black, bool newline = false, bool timestamp = false)
{
//lock (locker)
{
Console.ForegroundColor = c;
Console.BackgroundColor = b;
var msg = $"{(timestamp ? $"[{DateTime.Now}]: " : "")}{text}{(newline ? "\n" : "")}";
Console.Write(msg);
Console.ResetColor();
OnLog?.Invoke(msg);
}
}
public static void LogMsgTag(string tag, string text, System.Drawing.Color tagc, System.Drawing.Color textc)
{
var msg = $"[{DateTime.Now}]: [{tag}] {text}\n";
Console.Write(msg);
OnLog?.Invoke(msg);
}
public static void LogMsgTag(string tag, string text, ConsoleColor tagc = ConsoleColor.White, ConsoleColor textc = ConsoleColor.White, ConsoleColor tagb = ConsoleColor.Black, ConsoleColor textb = ConsoleColor.Black, bool newline = true)
{
lock (locker)
{
//if (tagc != ConsoleColor.White)
LogMsg(tag, tagc, tagb, false, true);
LogMsg(" ", false, false);
//else
// LogMsg(tag + " ", false, true);
//if (textc != ConsoleColor.White)
LogMsg(text, textc, textb, newline);
//else
// LogMsg(text, true);
}
}
public static void LogMsgAt(string text, int x, int y)
{
lock (locker)
{
var cu = Console.GetCursorPosition();
Console.Write(text);
Console.MoveBufferArea(cu.Left, cu.Top, Console.BufferWidth, 1, x, y);
Console.SetCursorPosition(cu.Left, cu.Top);
}
}
}
}