1using System.Globalization;
4using System.Runtime.InteropServices;
15 public const string fName =
"GameLogSink";
19 throw new InvalidOperationException(
"GameLogSink already created.");
26 if (!fileInfo.Exists) {
30 if (fileInfo.Length > 2097152)
33 ? CultureInfo.CurrentCulture
40 fileInfo.MoveTo(destination,
true);
44 m_stream = fileInfo.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.Read);
50 catch (Exception ex) {
51#if !MOBILE && !BROWSER
56#pragma warning disable CA1416
57 Console.Title =
"Logs of Survivalcraft API";
58#pragma warning restore CA1416
59 errorOfInstantiation = $
"Error creating GameLogSink, and a console window for viewing logs is created. Reason: {ex.Message}";
74 m_stream.Position = Math.Max(
m_stream.Position - bytesCount, 0L);
75 return new StreamReader(
m_stream).ReadToEnd();
89 m_stream.Position = Math.Max(
m_stream.Position - bytesCount, 0L);
90 StreamReader streamReader =
new(
m_stream);
91 List<string> list =
new();
93 string text = streamReader.ReadLine();
102 m_stream.Position =
m_stream.Length;
112 case LogType.Debug: value =
"DEBUG: ";
break;
113 case LogType.Verbose: value =
"INFO: ";
break;
114 case LogType.Information: value =
"INFO: ";
break;
115 case LogType.Warning: value =
"WARNING: ";
break;
116 case LogType.Error: value =
"ERROR: ";
break;
117 default: value =
string.Empty;
break;
119 m_writer.Write(DateTime.Now.ToString(
"HH:mm:ss.fff"));
140 [DllImport(
"kernel32.dll", SetLastError =
true)]
141 static extern bool AllocConsole();
143 [DllImport(
"kernel32.dll", SetLastError =
true)]
144 static extern bool FreeConsole();
static void Error(object message)
static void Information(object message)
static void CreateDirectory(string path)
static bool DirectoryExists(string path)
static Stream OpenFile(string path, OpenFileMode openFileMode)
static string SanitizeFileName(string filename, string replacement="-")
static FileInfo GetFileInfo(string path)
static string ProcessPath(string path, bool writeAccess, bool failIfApp)
static string CombinePaths(params string[] paths)
static List< string > GetRecentLogLines(int bytesCount)
static string GetRecentLog(int bytesCount)
static string errorOfInstantiation
static StreamWriter m_writer
void Log(LogType type, string message)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
static string SystemLanguage