-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathDebugLog.cs
67 lines (62 loc) · 1.8 KB
/
DebugLog.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
using System;
using System.IO;
using System.Net.Http.Headers;
using System.Threading;
namespace ClubmanSharp
{
public enum LogType
{
Main,
Menu,
Driv,
Trck
}
public class DebugLog
{
public static bool isActiveMain = false;
public static bool isActiveMenu = false;
public static bool isActiveDriver = false;
public static bool isActiveTrack = false;
private readonly static string path = Path.Combine(Directory.GetCurrentDirectory(), "debug.log");
public static void SetActive(bool state, LogType type)
{
switch (type)
{
case LogType.Main:
isActiveMain = state;
break;
case LogType.Menu:
isActiveMenu = state;
break;
case LogType.Driv:
isActiveDriver = state;
break;
}
}
public static void Log(string msg, LogType type)
{
if (type == LogType.Main && !isActiveMain)
return;
if (type == LogType.Menu && !isActiveMenu)
return;
if (type == LogType.Driv && !isActiveDriver)
return;
if (type == LogType.Trck && !isActiveTrack)
return;
byte retryCount = 0;
while (retryCount < 10)
{
try
{
File.AppendAllText(path, $"[{DateTime.Now:yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffff}] {type}: {msg}\n");
break;
}
catch (IOException)
{
Thread.Sleep(100);
retryCount++;
}
}
}
}
}