Merge branch 'master' of http://192.168.0.12:13000/sc/SunlightAggregationManager
This commit is contained in:
commit
8aa79a46e3
4 files changed
+170
-113
No files matched your search
+107
-59
@@ -1,85 +1,133 @@
|
||||
using System;
|
||||
using SunlightAggregationManager.View;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace SunlightAggregationManager.UserClass
|
||||
{
|
||||
public class LogGing
|
||||
{
|
||||
public class LOGinf
|
||||
{
|
||||
public required string Logpath { get; set; }
|
||||
public required string LogPath { get; set; }
|
||||
public required string Log_time { get; set; }
|
||||
public required object DAT { get; set; }
|
||||
}
|
||||
static Queue<LOGinf> LogGingQueue = new Queue<LOGinf>();
|
||||
static Queue<LOGinf> ERRQueue = new Queue<LOGinf>();
|
||||
static Queue<LOGinf> ExchangeQueue = new Queue<LOGinf>();
|
||||
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") + "]:";
|
||||
LOGinf ginf = new LOGinf
|
||||
{
|
||||
Logpath = System.Environment.CurrentDirectory + "\\Log",//日志文件目录
|
||||
LogPath = "" + System.Environment.CurrentDirectory + "\\Log\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt",//日志文件
|
||||
Log_time = "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:",
|
||||
DAT = dat
|
||||
};
|
||||
LogGingQueue.Enqueue(ginf);
|
||||
|
||||
if (Directory.Exists(logpath))//检查日志路径
|
||||
if(LogGingQueue.Count==1) LogGingQueueW();
|
||||
}
|
||||
public static async void LogGingQueueW()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (!File.Exists(logPath))//检查日志文件并写入启动日志
|
||||
try
|
||||
{
|
||||
FileStream fs = new FileStream(logPath, FileMode.CreateNew, FileAccess.Write);//创建写入文件
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine(Log_time + dat);
|
||||
wr.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
LOGinf inf = LogGingQueue.Dequeue();
|
||||
|
||||
if (Directory.Exists(inf.Logpath))//检查日志路径
|
||||
{
|
||||
FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write);
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine(Log_time + dat);
|
||||
wr.Close();
|
||||
if (!File.Exists(inf.LogPath))//检查日志文件并写入启动日志
|
||||
{
|
||||
FileStream fs = new FileStream(inf.LogPath, FileMode.CreateNew, FileAccess.Write);//创建写入文件
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine(inf.Log_time + inf.DAT);
|
||||
wr.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
FileStream fs = new FileStream(inf.LogPath, FileMode.Append, FileAccess.Write);
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine(inf.Log_time + inf.DAT);
|
||||
wr.Close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DirectoryInfo directoryInfo = new DirectoryInfo(inf.Logpath);
|
||||
directoryInfo.Create();//创建日志路径
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DirectoryInfo directoryInfo = new DirectoryInfo(logpath);
|
||||
directoryInfo.Create();//创建日志路径
|
||||
catch (Exception ) { }
|
||||
if (LogGingQueue.Count == 0) break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ERRDATA(System.Exception dat)
|
||||
{
|
||||
string Log_time = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
string logpath = System.Environment.CurrentDirectory + "\\ERR";//日志文件目录
|
||||
// string logPathtxt = "" + System.Environment.CurrentDirectory + "\\Log\\"+ Log_time + "Log.txt";//日志文件
|
||||
// System.IO.DirectoryInfo log = new System.IO.DirectoryInfo();//生成日志文件目录
|
||||
string log_path = logpath + "\\ERR" + Log_time + ".txt";
|
||||
string Log_timehms = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
if (Directory.Exists(logpath))//检查日志路径
|
||||
{
|
||||
LOGinf ginf = new LOGinf
|
||||
{
|
||||
if (!File.Exists(log_path))//检查文件并写入
|
||||
{
|
||||
// FileStream fs = new FileStream(log_path, FileMode.CreateNew, FileAccess.Write);//创建文件
|
||||
// StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
// wr.Close();
|
||||
FileStream fil = new FileStream(log_path, FileMode.CreateNew, FileAccess.Write);//创建写入文件
|
||||
StreamWriter wfil = new StreamWriter(fil);//创建文件
|
||||
wfil.WriteLine("[" + Log_timehms + "];[Error] ||" + Environment.NewLine.ToString());
|
||||
wfil.WriteLine("[" + Log_timehms + "];[Error source] ||" + dat.Source.ToString() + Environment.NewLine.ToString());
|
||||
wfil.WriteLine("[" + Log_timehms + "];[Error message] ||" + dat.Message.ToString() + Environment.NewLine.ToString());
|
||||
wfil.WriteLine("[" + Log_timehms + "];[Error area] ||" + dat.StackTrace.ToString());
|
||||
wfil.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
FileStream fs = new FileStream(log_path, FileMode.Append, FileAccess.Write);//创建写入文件
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine("[" + Log_timehms + "];[Error] ||" + Environment.NewLine.ToString());
|
||||
wr.WriteLine("[" + Log_timehms + "];[Error source] ||" + dat.ToString() + Environment.NewLine.ToString());
|
||||
wr.WriteLine("[" + Log_timehms + "];[Error message] ||" + dat.Message.ToString() + Environment.NewLine.ToString());
|
||||
wr.WriteLine("[" + Log_timehms + "];[Error area] ||" + dat.ToString());
|
||||
wr.Close();
|
||||
}
|
||||
}
|
||||
else
|
||||
Logpath = System.Environment.CurrentDirectory + "\\ERR",//日志文件目录
|
||||
LogPath = "" + System.Environment.CurrentDirectory + "\\ERR\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt",//日志文件
|
||||
Log_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
DAT = dat
|
||||
};
|
||||
ERRQueue.Enqueue(ginf);
|
||||
|
||||
if (ERRQueue.Count == 1) ERRQueueW();
|
||||
}
|
||||
public static async void ERRQueueW()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
DirectoryInfo directoryInfo = new DirectoryInfo(logpath);
|
||||
directoryInfo.Create();
|
||||
try
|
||||
{
|
||||
LOGinf inf = ERRQueue.Dequeue();
|
||||
Exception dat = (Exception)inf.DAT;
|
||||
|
||||
if (Directory.Exists(inf.Logpath))//检查日志路径
|
||||
{
|
||||
if (!File.Exists(inf.LogPath))//检查文件并写入
|
||||
{
|
||||
// FileStream fs = new FileStream(log_path, FileMode.CreateNew, FileAccess.Write);//创建文件
|
||||
// StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
// wr.Close();
|
||||
FileStream fil = new FileStream(inf.LogPath, FileMode.CreateNew, FileAccess.Write);//创建写入文件
|
||||
StreamWriter wfil = new StreamWriter(fil);//创建文件
|
||||
wfil.WriteLine("[" + inf.Log_time + "];[Error] ||" + Environment.NewLine.ToString());
|
||||
wfil.WriteLine("[" + inf.Log_time + "];[Error source] ||" + dat.Source.ToString() + Environment.NewLine.ToString());
|
||||
wfil.WriteLine("[" + inf.Log_time + "];[Error message] ||" + dat.Message.ToString() + Environment.NewLine.ToString());
|
||||
wfil.WriteLine("[" + inf.Log_time + "];[Error area] ||" + dat.StackTrace.ToString());
|
||||
wfil.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
FileStream fs = new FileStream(inf.LogPath, FileMode.Append, FileAccess.Write);//创建写入文件
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine("[" + inf.Log_time + "];[Error] ||" + Environment.NewLine.ToString());
|
||||
wr.WriteLine("[" + inf.Log_time + "];[Error source] ||" + dat.ToString() + Environment.NewLine.ToString());
|
||||
wr.WriteLine("[" + inf.Log_time + "];[Error message] ||" + dat.Message.ToString() + Environment.NewLine.ToString());
|
||||
wr.WriteLine("[" + inf.Log_time + "];[Error area] ||" + dat.ToString());
|
||||
wr.Close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DirectoryInfo directoryInfo = new DirectoryInfo(inf.Logpath);
|
||||
directoryInfo.Create();
|
||||
}
|
||||
}
|
||||
catch (Exception) { }
|
||||
if (ERRQueue.Count == 0) break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ExchangeDATA(string dat)
|
||||
{
|
||||
string Log_time = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
|
||||
Reference in new issue
Block a user