-
Notifications
You must be signed in to change notification settings - Fork 2
/
ClsDebug.cs
84 lines (78 loc) · 2.8 KB
/
ClsDebug.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
82
83
84
using System.Diagnostics;
using System.Globalization;
using System.Windows.Forms;
namespace WinSize4
{
public static class ClsDebug
{
public static bool Debug = false;
public static string _text = "";
public static void ClearLog()
{
string _path = Environment.GetEnvironmentVariable("LocalAppData") + "\\WinSize4";
Directory.CreateDirectory(_path);
string _FileName = "Debug.txt";
if (File.Exists(Path.Combine(_path, _FileName)))
{
File.Delete(Path.Combine(_path, _FileName));
}
_text = "";
}
public static void AddText(string Text)
{
string dt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);
_text += dt + " " + Text + "\n";
}
public static void LogText()
{
string _path = Environment.GetEnvironmentVariable("LocalAppData") + "\\WinSize4";
string dt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);
Directory.CreateDirectory(_path);
string _FileName = "Debug.txt";
if (Debug)
{
using (var writer = new StreamWriter(_path + "\\" + _FileName, true))
{
writer.WriteLine(dt + " " + _text);
}
}
_text = "";
}
public static void LogNow(string Text)
{
string dt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);
string _path = Environment.GetEnvironmentVariable("LocalAppData") + "\\WinSize4";
Directory.CreateDirectory(_path);
string _FileName = "Debug.txt";
if (Debug)
{
using (var writer = new StreamWriter(_path + "\\" + _FileName, true))
{
writer.WriteLine(dt + " " + Text);
}
}
}
public static void LogToEvent(Exception ex, EventLogEntryType Type, string text)
{
if (ex.StackTrace == null)
{
EventLog.WriteEntry("WinSize4", text, Type, 1);
if (Debug)
{
Console.WriteLine(text);
}
}
else
{
StackTrace st = new StackTrace(ex, true);
StackFrame frame = st.GetFrame(0);
int line = frame.GetFileLineNumber();
EventLog.WriteEntry("WinSize4", ex.Message + "\n" + st.ToString() + text, Type, 1);
if (Debug)
{
Console.WriteLine(ex.Message + "\n" + st.ToString() + "\n" + text);
}
}
}
}
}