修改日志文件函数调用逻辑
This commit is contained in:
commit
6a706ea804
8 files changed
+86
-64
No files matched your search
@@ -23,7 +23,7 @@ namespace formula_manage.EX
|
||||
public ExProgram()
|
||||
{
|
||||
InitializeComponent();
|
||||
Log.SetTextControl(textLog);
|
||||
LogDataRead.SetTextControl(textLog);
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-50
@@ -27,11 +27,6 @@ namespace formula_manage
|
||||
/// </summary>
|
||||
public partial class Login : Window
|
||||
{
|
||||
|
||||
string logpath = System.Environment.CurrentDirectory + "\\Log";//日志文件目录
|
||||
string logPath = "" + System.Environment.CurrentDirectory + "\\Log\\Log.txt";//日志文件
|
||||
string Log_time = "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:";
|
||||
|
||||
public string INIPath = Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "formula.ini"; //配置文件路径
|
||||
|
||||
DataTable logindataTable = new DataTable(); //建立login缓存
|
||||
@@ -41,31 +36,12 @@ namespace formula_manage
|
||||
WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||
InitializeComponent();
|
||||
|
||||
System.IO.DirectoryInfo log = new System.IO.DirectoryInfo(@logpath);//生成日志文件目录
|
||||
if (!File.Exists(logPath))//检查日志文件并写入启动日志
|
||||
{
|
||||
FileStream fs = new FileStream(logPath, FileMode.CreateNew, FileAccess.Write);//创建写入文件
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine(Log_time + "FORMULA_start");
|
||||
wr.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write);
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine(Log_time + "FORMULA_start");
|
||||
wr.Close();
|
||||
}
|
||||
|
||||
UserClass.LogGing.LogGingDATA("FORMULA_start");
|
||||
}
|
||||
|
||||
private void Button_Click(object sender, RoutedEventArgs e) //退出按钮事件
|
||||
{
|
||||
FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write);
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine(Log_time + "FORMULA_LogStop");
|
||||
wr.Close();
|
||||
this.Close();
|
||||
UserClass.LogGing.LogGingDATA("FORMULA_LogStop");
|
||||
}
|
||||
|
||||
private void Button_Click_1(object sender, RoutedEventArgs e) //登录按钮事件
|
||||
@@ -87,10 +63,7 @@ namespace formula_manage
|
||||
MainWindow Main = new MainWindow();
|
||||
window.Close();
|
||||
|
||||
FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write);
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine(Log_time + "LOGon = ENGINEER");
|
||||
wr.Close();
|
||||
UserClass.LogGing.LogGingDATA("LOGon = ENGINEER");
|
||||
|
||||
Main.ShowDialog();//实例化并置顶打开窗口
|
||||
}
|
||||
@@ -111,10 +84,7 @@ namespace formula_manage
|
||||
MainWindow Main = new MainWindow();
|
||||
window.Close();
|
||||
|
||||
FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write);
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine(Log_time + "LOGon = " + user);
|
||||
wr.Close();
|
||||
UserClass.LogGing.LogGingDATA("LOGon = " + user);
|
||||
|
||||
Main.ShowDialog();//实例化并置顶打开窗口
|
||||
}
|
||||
@@ -166,10 +136,7 @@ namespace formula_manage
|
||||
{
|
||||
EXLINK.Background = Brushes.Red;
|
||||
System.Windows.MessageBox.Show("扩展程序未启动");
|
||||
FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write);
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:" + "EX = FALL_TO_START");
|
||||
wr.Close();
|
||||
UserClass.LogGing.LogGingDATA("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:" + "EX = FALL_TO_START");
|
||||
}
|
||||
}
|
||||
try
|
||||
@@ -207,10 +174,7 @@ namespace formula_manage
|
||||
//Windows.Sql sql = new Windows.Sql();
|
||||
//sql.ShowDialog();//实例化并置顶打开数据库设置窗口
|
||||
|
||||
FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write);
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:" + "DISPENLINK = ConnectFailed");
|
||||
wr.Close();
|
||||
UserClass.LogGing.LogGingDATA("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:" + "DISPENLINK = ConnectFailed");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -244,10 +208,7 @@ namespace formula_manage
|
||||
//Windows.Sql sql = new Windows.Sql();
|
||||
//sql.ShowDialog();//实例化并置顶打开数据库设置窗口
|
||||
|
||||
FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write);
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:" + "DBCLINK = ConnectFailed");
|
||||
wr.Close();
|
||||
UserClass.LogGing.LogGingDATA("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:" + "DBCLINK = ConnectFailed");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -275,10 +236,7 @@ namespace formula_manage
|
||||
catch (Exception)
|
||||
{
|
||||
System.Windows.MessageBox.Show("请求信息失败,检查连接");
|
||||
FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write);
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:" + "USER = NoData");
|
||||
wr.Close();
|
||||
UserClass.LogGing.LogGingDATA("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:" + "USER = NoData");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-10
@@ -248,10 +248,6 @@ namespace formula_manage
|
||||
}
|
||||
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) //窗口关闭事件
|
||||
{
|
||||
string logpath = System.Environment.CurrentDirectory + "\\Log";//日志文件目录
|
||||
string logPath = "" + System.Environment.CurrentDirectory + "\\Log\\Log.txt";//日志文件
|
||||
string Log_time = "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:";
|
||||
|
||||
if (!quit)
|
||||
{
|
||||
MessageBoxResult result = System.Windows.MessageBox.Show("您确定要退出吗?", "SUNLIGHT", MessageBoxButton.OKCancel, MessageBoxImage.None, MessageBoxResult.Cancel);
|
||||
@@ -262,13 +258,10 @@ namespace formula_manage
|
||||
}
|
||||
}
|
||||
|
||||
System.IO.DirectoryInfo log = new System.IO.DirectoryInfo(@logpath);//生成日志文件目录
|
||||
FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write);
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
// wr.WriteLine(Log_time + "HttpSERVER_STOP");
|
||||
// UserClass.LogGing.LogGingDATA(Log_time + "HttpSERVER_STOP");
|
||||
// UserClass.HttpSERVER.Stop(); //停止网络通信
|
||||
wr.WriteLine(Log_time + "FORMULA_STOP");
|
||||
wr.Close();
|
||||
UserClass.LogGing.LogGingDATA("FORMULA_STOP");
|
||||
|
||||
}
|
||||
private void SearchBox_OnKeyDownd(object sender, System.Windows.Input.KeyEventArgs e) //回车跳转功能
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace formula_manage.UserClass
|
||||
{
|
||||
internal class DataTableToObservableCollection
|
||||
internal class DataTableToObservableCollection //数据表到可观察集合
|
||||
{
|
||||
public ObservableCollection<T> ToObservableCollection<T>(DataTable dt) where T : class, new()
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Windows.Media;
|
||||
|
||||
namespace formula_manage.UserClass
|
||||
{
|
||||
public static class Log
|
||||
public static class LogDataRead
|
||||
{
|
||||
private const int MaxCount = 1000;
|
||||
private static int Count = 0;
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace formula_manage.UserClass
|
||||
{
|
||||
public class LogGing
|
||||
{
|
||||
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") + "]:";
|
||||
|
||||
System.IO.DirectoryInfo log = new System.IO.DirectoryInfo(@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
|
||||
{
|
||||
FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write);
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine(Log_time + dat);
|
||||
wr.Close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net.NetworkInformation;
|
||||
|
||||
namespace formula_manage.UserClass
|
||||
{
|
||||
public class get_local_ip_address
|
||||
{
|
||||
public static string getLocalIPAddressWithNetworkInterface(NetworkInterfaceType _type)//获取本机ip并以字符串方式返回
|
||||
{
|
||||
string output = "";
|
||||
foreach (NetworkInterface item in NetworkInterface.GetAllNetworkInterfaces())
|
||||
{
|
||||
if (item.NetworkInterfaceType == _type && item.OperationalStatus == OperationalStatus.Up)
|
||||
{
|
||||
foreach (UnicastIPAddressInformation ip in item.GetIPProperties().UnicastAddresses)
|
||||
{
|
||||
if (ip.Address.AddressFamily == AddressFamily.InterNetwork)
|
||||
{
|
||||
output = ip.Address.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -443,10 +443,12 @@
|
||||
<Compile Include="UserClass\Code128.cs" />
|
||||
<Compile Include="UserClass\CRCcheck16.cs" />
|
||||
<Compile Include="UserClass\DataGridHelper.cs" />
|
||||
<Compile Include="UserClass\get_local_ip_address.cs" />
|
||||
<Compile Include="UserClass\HardwareSN.cs" />
|
||||
<Compile Include="UserClass\LogGing.cs" />
|
||||
<Compile Include="UserClass\TCPServer.cs" />
|
||||
<Compile Include="UserClass\IniFile.cs" />
|
||||
<Compile Include="UserClass\Log.cs" />
|
||||
<Compile Include="UserClass\LogDataRead.cs" />
|
||||
<Compile Include="UserClass\MD5check.cs" />
|
||||
<Compile Include="UserClass\PressKey.cs" />
|
||||
<Compile Include="UserClass\DataTableForToObservableCollection.cs" />
|
||||
|
||||
Reference in new issue
Block a user