51 lines
1.6 KiB
C#
51 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AIProofread
|
|
{
|
|
public class Logger
|
|
{
|
|
private static readonly string AppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="msg"></param>
|
|
public static void Log(string msg)
|
|
{
|
|
string path = Config.APP_LOG_PATH + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
|
if (!Directory.Exists(Config.APP_LOG_PATH))
|
|
{
|
|
Directory.CreateDirectory(Config.APP_LOG_PATH);
|
|
}
|
|
StreamWriter streamWriter = File.AppendText(path);
|
|
streamWriter.WriteLine("***************************[" + (Config.IS_WPS ? "WPS" : "WORD") + "]***************************");
|
|
streamWriter.WriteLine("消息:" + msg);
|
|
streamWriter.WriteLine("时间:" + DateTime.Now.ToString("yyyy - MM - dd HH: mm:ss"));
|
|
streamWriter.WriteLine();
|
|
streamWriter.Flush();
|
|
streamWriter.Close();
|
|
streamWriter.Dispose();
|
|
}
|
|
public static void Log( Exception e)
|
|
{
|
|
Log(e.StackTrace);
|
|
}
|
|
public static void Log(string tag, Exception e)
|
|
{
|
|
Log(tag + "\n" + e.StackTrace);
|
|
}
|
|
|
|
public static void LogToWeb(string msg)
|
|
{
|
|
if (Config.RUN_IN_DEBUG)
|
|
{
|
|
Globals.ThisAddIn.SendMessageToWeb("DEBUG-LOG", msg);
|
|
}
|
|
}
|
|
}
|
|
}
|