This repository has been archived by the owner on Jul 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogger.cs
78 lines (64 loc) · 1.72 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
78
using System.Diagnostics;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
namespace DriveFiller
{
internal static class Logger
{
private static StringBuilder logger = new();
private static bool active = false;
private static string logFileName
{
get
{
return Regex.Replace($"DriveFiller-{DateTime.Now}.log", "[\\/:*?\"<>|]", "-").Replace(" ", "_");
}
}
internal static void SetActive(bool value)
{
active = value;
logger.Clear();
}
private static string GetLogPath()
{
string? dir = Path.GetDirectoryName(Environment.ProcessPath);
if (dir == null)
{
return Path.GetTempPath();
}
return Path.Combine(dir, logFileName);
}
internal static void AddLog(string info)
{
if (!active)
{
return;
}
logger.AppendLine(info);
}
internal static void AddSpacedLog(string info)
{
if (!active)
{
return;
}
logger.AppendLine();
logger.AppendLine(info);
logger.AppendLine();
}
internal static void WriteLogToDisk(string path = "")
{
if (!active)
{
return;
}
if (path == string.Empty)
{
path = GetLogPath();
}
File.WriteAllText(path, logger.ToString());
InputHelper.SpaceOutText($"Saved log file in {path}!");
}
}
}