-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDebug.cs
76 lines (71 loc) · 2.36 KB
/
Debug.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
using Decal.Adapter;
using System;
using System.IO;
using System.Text;
namespace ACManager
{
/// <summary>
/// General debugging class.
/// Can write to debug file, or just output to chat.
/// </summary>
public static class Debug
{
private static string DebugFileName { get { return "acm_debug.log"; } }
private static string DebugFilePath { get; set; }
private static string ErrorFileName { get { return "acm_errors.log"; } }
private static string ErrorFilePath { get; set; }
/// <summary>
/// Sets the file paths to print debug/exceptions statements to.
/// </summary>
public static void Init(string path)
{
ErrorFilePath = Path.Combine(path, ErrorFileName);
DebugFilePath = Path.Combine(path, DebugFileName);
}
/// <summary>
/// Function to debug errors to a file.
/// </summary>
public static void LogException(Exception e)
{
try
{
StringBuilder sb = new StringBuilder();
sb.Append(DateTime.Now.ToString());
sb.Append(" --- ");
sb.Append(e.StackTrace);
sb.Append(Environment.NewLine);
File.AppendAllText(ErrorFilePath, sb.ToString());
}
catch (Exception ex)
{
CoreManager.Current.Actions.AddChatText(ex.Message, 5, 1);
}
}
/// <summary>
/// Function to write in-line debug statements to a file.
/// </summary>
public static void ToFile(string message)
{
try
{
string text = $"{DateTime.Now} --- {message}";
File.AppendAllText(DebugFilePath, text);
}
catch (Exception e)
{
CoreManager.Current.Actions.AddChatText(e.Message, 5, 1);
}
}
/// <summary>
/// Sends a chat message in-game. This is visible only to the client running this bot.
/// This is used for debugging or sending info to the user.
/// </summary>
public static void ToChat(string text)
{
if (!string.IsNullOrEmpty(text))
{
CoreManager.Current.Actions.AddChatText($"<ACManager> {text}", 5, 1);
}
}
}
}