InkCanvasForClass/Ink Canvas/Helpers/LogHelper.cs

58 lines
1.4 KiB
C#
Raw Normal View History

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 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;
}
2023-05-17 21:51:13 +08:00
try
{
var file = App.RootPath + LogFile;
if (!Directory.Exists(App.RootPath))
{
Directory.CreateDirectory(App.RootPath);
}
StreamWriter sw = new StreamWriter(file, true);
sw.WriteLine(string.Format("{0} [{1}] {2}", DateTime.Now.ToString("O"), strLogType, str));
sw.Close();
}
catch { }
2021-12-16 01:21:41 +08:00
}
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
}
}
}