Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
Log.cs
浏览该文件的文档.
1namespace Engine {
2 public static class Log {
3 static object m_lock;
4
5 static List<ILogSink> m_logSinks;
6
7 public static LogType MinimumLogType { get; set; }
8
9 static Log() {
10 m_lock = new object();
11 m_logSinks = [];
13 MinimumLogType = LogType.Information;
14 }
15
16 public static void Write(LogType type, string message) {
17 lock (m_lock) {
18 if (m_logSinks.Count > 0
19 && type >= MinimumLogType) {
20 foreach (ILogSink logSink in m_logSinks) {
21 try {
22 logSink.Log(type, message);
23 }
24 catch {
25 // ignored
26 }
27 }
28 }
29 }
30 }
31
32 public static void Debug(object message) {
33 Write(LogType.Debug, message != null ? message.ToString() : "null");
34 }
35
36 public static void Debug(string message) {
37 Write(LogType.Debug, message);
38 }
39
40 public static void Debug(string format, params object[] parameters) {
41 Write(LogType.Debug, string.Format(format, parameters));
42 }
43
44 public static void Verbose(object message) {
45 Write(LogType.Verbose, message != null ? message.ToString() : "null");
46 }
47
48 public static void Verbose(string message) {
49 Write(LogType.Verbose, message);
50 }
51
52 public static void Verbose(string format, params object[] parameters) {
53 Write(LogType.Verbose, string.Format(format, parameters));
54 }
55
56 public static void Information(object message) {
57 Write(LogType.Information, message != null ? message.ToString() : "null");
58 }
59
60 public static void Information(string message) {
61 Write(LogType.Information, message);
62 }
63
64 public static void Information(string format, params object[] parameters) {
65 Write(LogType.Information, string.Format(format, parameters));
66 }
67
68 public static void Warning(object message) {
69 Write(LogType.Warning, message != null ? message.ToString() : "null");
70 }
71
72 public static void Warning(string message) {
73 Write(LogType.Warning, message);
74 }
75
76 public static void Warning(string format, params object[] parameters) {
77 Write(LogType.Warning, string.Format(format, parameters));
78 }
79
80 public static void Error(object message) {
81 Write(LogType.Error, message != null ? message.ToString() : "null");
82 }
83
84 public static void Error(string message) {
85 Write(LogType.Error, message);
86#if !MOBILE
87 Window.TitleSuffix = $" #{message}";
88#endif
89 }
90
91 public static void Error(string format, params object[] parameters) {
92 Write(LogType.Error, string.Format(format, parameters));
93 }
94
95 public static void Warning(Exception e) {
96 Write(LogType.Warning, $"{e.Message}↓");
97 Write(LogType.Warning, e.ToString());
98 }
99
100 public static void Error(Exception e) {
101 Write(LogType.Error, $"{e.Message}↓");
102 if (e is NullReferenceException e_null) {
103 #pragma warning disable IL2026
104 Write(LogType.Error, $"NullReferenceException: {e_null.TargetSite?.DeclaringType?.Name}.{e_null.TargetSite?.Name} is null");
105 #pragma warning restore IL2026
106 }
107 Write(LogType.Error, e.ToString());
108 }
109
110 public static void AddLogSink(ILogSink logSink) {
111 lock (m_lock) {
112 if (!m_logSinks.Contains(logSink)) {
113 m_logSinks.Add(logSink);
114 }
115 }
116 }
117
118 public static void RemoveLogSink(ILogSink logSink) {
119 lock (m_lock) {
120 m_logSinks.Remove(logSink);
121 }
122 }
123
124 public static void RemoveAllLogSinks() {
125 lock (m_lock) {
126 m_logSinks.Clear();
127 }
128 }
129
130 public static void Dispose() {
131 lock (m_lock) {
132 foreach (ILogSink logSink in m_logSinks) {
133 if (logSink is IDisposable disposable) {
134 disposable.Dispose();
135 }
136 }
137 m_logSinks.Clear();
138 }
139 }
140 }
141}
static void Debug(string message)
定义 Log.cs:36
static void Error(Exception e)
定义 Log.cs:100
static void Error(object message)
定义 Log.cs:80
static void Verbose(string format, params object[] parameters)
定义 Log.cs:52
static Log()
定义 Log.cs:9
static void Information(string format, params object[] parameters)
定义 Log.cs:64
static object m_lock
定义 Log.cs:3
static void Verbose(string message)
定义 Log.cs:48
static void Information(string message)
定义 Log.cs:60
static void RemoveLogSink(ILogSink logSink)
定义 Log.cs:118
static void Error(string format, params object[] parameters)
定义 Log.cs:91
static void Error(string message)
定义 Log.cs:84
static void Debug(string format, params object[] parameters)
定义 Log.cs:40
static void Dispose()
定义 Log.cs:130
static void Information(object message)
定义 Log.cs:56
static void Warning(string message)
定义 Log.cs:72
static void Warning(string format, params object[] parameters)
定义 Log.cs:76
static void Warning(Exception e)
定义 Log.cs:95
static LogType MinimumLogType
定义 Log.cs:7
static List< ILogSink > m_logSinks
定义 Log.cs:5
static void Verbose(object message)
定义 Log.cs:44
static void Warning(object message)
定义 Log.cs:68
static void Write(LogType type, string message)
定义 Log.cs:16
static void Debug(object message)
定义 Log.cs:32
static void AddLogSink(ILogSink logSink)
定义 Log.cs:110
static void RemoveAllLogSinks()
定义 Log.cs:124
static string TitleSuffix
void Log(LogType type, string message)