forked from kshman/DutyContent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogger.cs
77 lines (65 loc) · 1.83 KB
/
Logger.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
using System;
using System.Drawing;
using System.Text.RegularExpressions;
namespace DutyContent
{
static class Logger
{
private static readonly Regex ExceptionPattern = new Regex(@"\{(.+?)\}");
public static void Write(Color color, string fmt, params object[] prms)
{
if (Tab.LogForm.Self != null)
Tab.LogForm.Self.WriteLog(color, string.Format(fmt, prms));
}
public static void Write(string format, params object[] prms)
{
Write(Color.Black, format, prms);
}
public static void WriteCategory(Color color, string category, string fmt, params object[] prms)
{
if (Tab.LogForm.Self != null)
Tab.LogForm.Self.WriteLogSection(color, category, string.Format(fmt, prms));
}
public static void WriteCategory(string category, string format, params object[] prms)
{
Write(Color.Black, category, format, prms);
}
public static void L(string format, params object[] prms)
{
Write(Color.DarkBlue, format, prms);
}
// color
public static void C(Color color, int key, params object[] prms)
{
Write(color, Locale.Text(key, prms));
}
// info / black
public static void I(int key, params object[] prms)
{
Write(Color.Black, Locale.Text(key, prms));
}
// error / red
public static void E(int key, params object[] prms)
{
Write(Color.Red, Locale.Text(key, prms));
}
// gray
public static void Y(int key, params object[] prms)
{
Write(Color.Gray, Locale.Text(key, prms));
}
// exception
public static void Ex(Exception ex, int key, params object[] prms)
{
string text = Locale.Text(key, prms);
string msg = ExceptionPattern.Replace(ex.Message, "{{$1}}");
Write(Color.Red, $"{text}: {msg}");
}
// exception
public static void Ex(Exception ex)
{
string msg = ExceptionPattern.Replace(ex.Message, "{{$1}}");
Write(Color.Red, $"EX: {msg}");
}
}
}