2021-10-30 22:30:42 +08:00
|
|
|
|
using System;
|
2021-12-16 01:21:41 +08:00
|
|
|
|
using System.IO;
|
2021-10-30 22:30:42 +08:00
|
|
|
|
|
|
|
|
|
namespace Ink_Canvas.Helpers
|
|
|
|
|
{
|
|
|
|
|
class LogHelper
|
|
|
|
|
{
|
2021-12-16 01:21:41 +08:00
|
|
|
|
public static string LogFileName = "Log.txt";
|
|
|
|
|
public static string LogFile = "Log.txt";
|
2021-10-30 22:30:42 +08:00
|
|
|
|
|
|
|
|
|
public static void NewLog(string str)
|
|
|
|
|
{
|
2021-12-16 01:21:41 +08:00
|
|
|
|
WriteLogToFile(str, LogType.Info);
|
2021-10-30 22:30:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void NewLog(Exception ex)
|
|
|
|
|
{
|
2023-02-12 22:50:17 +08:00
|
|
|
|
|
2021-10-30 22:30:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-16 01:21:41 +08:00
|
|
|
|
public static void WriteLogToFile(string str, LogType logType = LogType.Info)
|
2021-10-30 22:30:42 +08:00
|
|
|
|
{
|
2021-12-16 01:21:41 +08:00
|
|
|
|
string strLogType = "Info";
|
|
|
|
|
switch (logType)
|
|
|
|
|
{
|
|
|
|
|
case LogType.Event:
|
|
|
|
|
strLogType = "Event";
|
|
|
|
|
break;
|
|
|
|
|
case LogType.Trace:
|
|
|
|
|
strLogType = "Trace";
|
|
|
|
|
break;
|
|
|
|
|
case LogType.Error:
|
|
|
|
|
strLogType = "Error";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
StreamWriter sw = new StreamWriter(LogFile, true);
|
|
|
|
|
sw.WriteLine(string.Format("{0} [{1}] {2}", DateTime.Now.ToString("O"), strLogType, str));
|
|
|
|
|
sw.Close();
|
|
|
|
|
}
|
2021-10-30 22:30:42 +08:00
|
|
|
|
|
2021-12-16 01:21:41 +08:00
|
|
|
|
public enum LogType
|
|
|
|
|
{
|
|
|
|
|
Info,
|
|
|
|
|
Trace,
|
|
|
|
|
Error,
|
|
|
|
|
Event
|
2021-10-30 22:30:42 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|