-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebug.cs
More file actions
106 lines (100 loc) · 3.22 KB
/
Debug.cs
File metadata and controls
106 lines (100 loc) · 3.22 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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace L2Script.Library
{
public enum LogType : byte
{
Error = 0x01,
Warning = 0x02,
Information = 0x03,
Exception = 0x04,
Unknown = 0xFF,
}
public static class Debug
{
public static void Exception(string Message, Exception ex) {
_print(LogType.Exception, Message);
_print(LogType.Exception, ex.ToString());
}
public static void Error(string Message)
{
_print(LogType.Error, Message);
}
public static void Information(string Message)
{
_print(LogType.Information, Message);
}
public static void Warning(string Message)
{
_print(LogType.Warning, Message);
}
public static void Unknown(string Message)
{
_print(LogType.Unknown, Message);
}
public static void Log(LogType Type, string Message)
{
_print(Type, Message);
}
public static void Blank()
{
Console.WriteLine();
_toFile("\r\n");
}
private static void _toFile(string line)
{
try
{
string text = "";
if (File.Exists("L2Script-debug.log"))
text = File.ReadAllText("L2Script-debug.log");
File.WriteAllText("L2Script-debug.log", text + line);
}
catch (Exception) { }
}
private static void _print(LogType lt, string Message)
{
string code = "***";
StringBuilder sb = new StringBuilder();
Console.ForegroundColor = ConsoleColor.White;
Console.Write("[");
sb.Append("[");
switch (lt)
{
case LogType.Error:
Console.ForegroundColor = ConsoleColor.DarkRed;
code = "ERR";
break;
case LogType.Warning:
Console.ForegroundColor = ConsoleColor.Blue;
code = "WRN";
break;
case LogType.Information:
Console.ForegroundColor = ConsoleColor.Green;
code = "INF";
break;
case LogType.Exception:
Console.ForegroundColor = ConsoleColor.Red;
code = "!E!";
break;
case LogType.Unknown:
Console.ForegroundColor = ConsoleColor.White;
code = "UNK";
break;
}
Console.Write(code);
sb.Append(code);
Console.ForegroundColor = ConsoleColor.White;
Console.Write("][");
sb.Append("][");
string time = DateTime.Now.ToLongTimeString();
Console.Write(time + "] ");
sb.Append(time + "] ");
Console.WriteLine(Message);
sb.Append(Message + "\r\n");
_toFile(sb.ToString());
}
}
}