-
Notifications
You must be signed in to change notification settings - Fork 8
/
ModLogger.cs
40 lines (37 loc) · 1.13 KB
/
ModLogger.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
using System;
using System.Diagnostics;
using System.IO;
namespace ModHelper
{
public static class ModLogger
{
private static StreamWriter fs = File.CreateText("ModLogger.log");
private static object locker = new object();
private static bool isShowConsole = false;
static ModLogger()
{
if (Environment.GetEnvironmentVariable("SHOW_CONSOLE_WINDOW") == "TRUE")
{
isShowConsole = true;
}
}
public static void Debug(object obj)
{
var frame = new StackTrace().GetFrame(1);
var className = frame.GetMethod().ReflectedType.Name;
var methodName = frame.GetMethod().Name;
AddLog(className, methodName, obj);
}
public static void AddLog(string className, string methodName,object obj)
{
var text = $"[{className}:{methodName}]: {obj}";
lock (locker)
{
if(isShowConsole)
Console.Error.WriteLine(text);
fs.WriteLine(text);
fs.Flush();
}
}
}
}