You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.9 KiB
70 lines
2.9 KiB
using DyeingComputer.ViewModel;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.IO;
|
|
using static DyeingComputer.UserClass.SqliteHelper;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;
|
|
|
|
namespace DyeingComputer.UserClass
|
|
{
|
|
public class LogGing
|
|
{
|
|
// private static SQLiteHelper SQLiteHelpers = null; //定义数据库
|
|
// private readonly static string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径
|
|
public static bool sqld=false;
|
|
public static void LogGingDATA(string dat)
|
|
{
|
|
string logpath = System.Environment.CurrentDirectory + "\\Log";//日志文件目录
|
|
string logPath = "" + System.Environment.CurrentDirectory + "\\Log\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";//日志文件
|
|
string Log_time = "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:";
|
|
|
|
if (Directory.Exists(logpath))//检查日志路径
|
|
{
|
|
if (!File.Exists(logPath))//检查日志文件并写入启动日志
|
|
{
|
|
FileStream fs = new FileStream(logPath, FileMode.CreateNew, FileAccess.Write);//创建写入文件
|
|
StreamWriter wr = new StreamWriter(fs);//创建文件
|
|
wr.WriteLine(Log_time + dat);
|
|
wr.Close();
|
|
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write);
|
|
StreamWriter wr = new StreamWriter(fs);//创建文件
|
|
wr.WriteLine(Log_time + dat);
|
|
wr.Close();
|
|
}
|
|
catch { }
|
|
}
|
|
}
|
|
else
|
|
{
|
|
DirectoryInfo directoryInfo = new DirectoryInfo(logpath);
|
|
directoryInfo.Create();//创建日志路径
|
|
}
|
|
}
|
|
public static void LogSQLDATA(string NAME, string api, string dat)
|
|
{
|
|
if (!sqld)
|
|
{
|
|
sqld = true;
|
|
//SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
string Log_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
Dictionary<string, object> logsql = new Dictionary<string, object>();
|
|
// 添加元素
|
|
logsql.Add("NAME", NAME);
|
|
logsql.Add("API", api);
|
|
logsql.Add("MESSAGE", dat);
|
|
logsql.Add("TIME", Log_time);
|
|
// SQLiteHelpers.Open(); //打开数据库
|
|
MainWindow.SQLiteHelpers.InsertData("SERVER", logsql);//行插入
|
|
//SQLiteHelpers.Close(); //关闭连接
|
|
sqld = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|