mirror of
https://github.com/DaKerboul/perun.git
synced 2026-08-09 18:05:40 +02:00
Improved logging
This commit is contained in:
@@ -9,7 +9,6 @@ class HardwareMonitorClass
|
|||||||
|
|
||||||
protected PerformanceCounter cpuCounter;
|
protected PerformanceCounter cpuCounter;
|
||||||
protected PerformanceCounter ramCounter;
|
protected PerformanceCounter ramCounter;
|
||||||
protected PerformanceCounter cputempCounter;
|
|
||||||
|
|
||||||
public HardwareMonitorClass()
|
public HardwareMonitorClass()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.IO;
|
|||||||
class LogController
|
class LogController
|
||||||
{
|
{
|
||||||
private static LogController _instance = new LogController(); // Singleton instance
|
private static LogController _instance = new LogController(); // Singleton instance
|
||||||
|
public int level; // Level of logging
|
||||||
|
|
||||||
public static LogController instance
|
public static LogController instance
|
||||||
{
|
{
|
||||||
@@ -14,40 +15,9 @@ class LogController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int level
|
|
||||||
{
|
|
||||||
get; // Get debug level
|
|
||||||
set; // Set debug level
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log error information
|
|
||||||
public void LogError(string strLog)
|
|
||||||
{
|
|
||||||
this.WriteLog(0, strLog);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log warning information
|
|
||||||
public void LogWarning(string strLog)
|
|
||||||
{
|
|
||||||
this.WriteLog(1, strLog);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log info information
|
|
||||||
public void LogInfo(string strLog)
|
|
||||||
{
|
|
||||||
this.WriteLog(2, strLog);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log debug information
|
|
||||||
public void LogDebug(string strLog)
|
|
||||||
{
|
|
||||||
this.WriteLog(3, strLog);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TBD - done via https://stackoverflow.com/questions/20185015/how-to-write-log-file-in-c
|
|
||||||
public void WriteLog(int logLevel, string strLog)
|
public void WriteLog(int logLevel, string strLog)
|
||||||
{
|
{
|
||||||
if (logLevel > this.level) return;
|
if (logLevel > this.level) return; // Check if we shall log it with the current log level, if not - exit
|
||||||
|
|
||||||
StreamWriter LogStreamWriter;
|
StreamWriter LogStreamWriter;
|
||||||
FileStream LogFileStream = null;
|
FileStream LogFileStream = null;
|
||||||
@@ -55,7 +25,7 @@ class LogController
|
|||||||
FileInfo LogFileInfo;
|
FileInfo LogFileInfo;
|
||||||
|
|
||||||
string LogFilePath = Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents") + "\\Perun\\";
|
string LogFilePath = Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents") + "\\Perun\\";
|
||||||
LogFilePath = LogFilePath + "Perun_Log_" + System.DateTime.Today.ToString("yyyyddMM") + "." + "txt";
|
LogFilePath = LogFilePath + "Perun_Log_" + Globals.AppInstanceID + "_" + System.DateTime.Today.ToString("yyyyddMM") + "." + "txt";
|
||||||
LogFileInfo = new FileInfo(LogFilePath);
|
LogFileInfo = new FileInfo(LogFilePath);
|
||||||
LogDirectoryInfo = new DirectoryInfo(LogFileInfo.DirectoryName);
|
LogDirectoryInfo = new DirectoryInfo(LogFileInfo.DirectoryName);
|
||||||
if (!LogDirectoryInfo.Exists) LogDirectoryInfo.Create();
|
if (!LogDirectoryInfo.Exists) LogDirectoryInfo.Create();
|
||||||
|
|||||||
@@ -48,7 +48,25 @@ internal class PerunHelper
|
|||||||
LogDirection = "^";
|
LogDirection = "^";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
LogDirection = " ";
|
LogDirection = "-";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert information about which log type we are curently handling
|
||||||
|
string LogType;
|
||||||
|
switch (logLevel)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
LogType = "E";
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
LogType = "W";
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
LogType = "I";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
LogType = "D";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +85,7 @@ internal class PerunHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add new entry
|
// Add new entry
|
||||||
arrLogHistory[arrLogHistory.Length - 1] = DateTime.Now.ToString("HH:mm:ss") + " " + LogDirection + " " + strEntryToAdd; // Add entry at the last position
|
arrLogHistory[arrLogHistory.Length - 1] = DateTime.Now.ToString("HH:mm:ss") + " " + LogDirection + " " + LogType + " " + strEntryToAdd; // Add entry at the last position
|
||||||
|
|
||||||
// Update control at my window
|
// Update control at my window
|
||||||
Globals.AppUpdateGUI = true;
|
Globals.AppUpdateGUI = true;
|
||||||
|
|||||||
@@ -100,7 +100,6 @@
|
|||||||
this.label27 = new System.Windows.Forms.Label();
|
this.label27 = new System.Windows.Forms.Label();
|
||||||
this.label20 = new System.Windows.Forms.Label();
|
this.label20 = new System.Windows.Forms.Label();
|
||||||
this.tim_HW_status = new System.Windows.Forms.Timer(this.components);
|
this.tim_HW_status = new System.Windows.Forms.Timer(this.components);
|
||||||
this.performanceCounter1 = new System.Diagnostics.PerformanceCounter();
|
|
||||||
this.con_GroupBox_1.SuspendLayout();
|
this.con_GroupBox_1.SuspendLayout();
|
||||||
this.con_GroupBox_2.SuspendLayout();
|
this.con_GroupBox_2.SuspendLayout();
|
||||||
this.con_GroupBox_3.SuspendLayout();
|
this.con_GroupBox_3.SuspendLayout();
|
||||||
@@ -114,7 +113,6 @@
|
|||||||
this.con_GroupBox_5.SuspendLayout();
|
this.con_GroupBox_5.SuspendLayout();
|
||||||
this.con_GroupBox_6.SuspendLayout();
|
this.con_GroupBox_6.SuspendLayout();
|
||||||
this.con_GroupBox_7.SuspendLayout();
|
this.con_GroupBox_7.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.performanceCounter1)).BeginInit();
|
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// con_List_Received
|
// con_List_Received
|
||||||
@@ -123,14 +121,14 @@
|
|||||||
this.con_List_Received.FormattingEnabled = true;
|
this.con_List_Received.FormattingEnabled = true;
|
||||||
this.con_List_Received.Items.AddRange(new object[] {
|
this.con_List_Received.Items.AddRange(new object[] {
|
||||||
"Not connected"});
|
"Not connected"});
|
||||||
this.con_List_Received.Location = new System.Drawing.Point(8, 57);
|
this.con_List_Received.Location = new System.Drawing.Point(8, 44);
|
||||||
this.con_List_Received.Name = "con_List_Received";
|
this.con_List_Received.Name = "con_List_Received";
|
||||||
this.con_List_Received.Size = new System.Drawing.Size(307, 108);
|
this.con_List_Received.Size = new System.Drawing.Size(307, 134);
|
||||||
this.con_List_Received.TabIndex = 0;
|
this.con_List_Received.TabIndex = 0;
|
||||||
//
|
//
|
||||||
// con_Button_Listen_ON
|
// con_Button_Listen_ON
|
||||||
//
|
//
|
||||||
this.con_Button_Listen_ON.Location = new System.Drawing.Point(342, 430);
|
this.con_Button_Listen_ON.Location = new System.Drawing.Point(342, 441);
|
||||||
this.con_Button_Listen_ON.Name = "con_Button_Listen_ON";
|
this.con_Button_Listen_ON.Name = "con_Button_Listen_ON";
|
||||||
this.con_Button_Listen_ON.Size = new System.Drawing.Size(86, 39);
|
this.con_Button_Listen_ON.Size = new System.Drawing.Size(86, 39);
|
||||||
this.con_Button_Listen_ON.TabIndex = 2;
|
this.con_Button_Listen_ON.TabIndex = 2;
|
||||||
@@ -141,7 +139,7 @@
|
|||||||
// con_Button_Listen_OFF
|
// con_Button_Listen_OFF
|
||||||
//
|
//
|
||||||
this.con_Button_Listen_OFF.Enabled = false;
|
this.con_Button_Listen_OFF.Enabled = false;
|
||||||
this.con_Button_Listen_OFF.Location = new System.Drawing.Point(434, 430);
|
this.con_Button_Listen_OFF.Location = new System.Drawing.Point(434, 441);
|
||||||
this.con_Button_Listen_OFF.Name = "con_Button_Listen_OFF";
|
this.con_Button_Listen_OFF.Name = "con_Button_Listen_OFF";
|
||||||
this.con_Button_Listen_OFF.Size = new System.Drawing.Size(86, 39);
|
this.con_Button_Listen_OFF.Size = new System.Drawing.Size(86, 39);
|
||||||
this.con_Button_Listen_OFF.TabIndex = 3;
|
this.con_Button_Listen_OFF.TabIndex = 3;
|
||||||
@@ -157,7 +155,7 @@
|
|||||||
this.con_GroupBox_1.Controls.Add(this.con_Button_Add_Marker);
|
this.con_GroupBox_1.Controls.Add(this.con_Button_Add_Marker);
|
||||||
this.con_GroupBox_1.Location = new System.Drawing.Point(342, 248);
|
this.con_GroupBox_1.Location = new System.Drawing.Point(342, 248);
|
||||||
this.con_GroupBox_1.Name = "con_GroupBox_1";
|
this.con_GroupBox_1.Name = "con_GroupBox_1";
|
||||||
this.con_GroupBox_1.Size = new System.Drawing.Size(324, 179);
|
this.con_GroupBox_1.Size = new System.Drawing.Size(324, 187);
|
||||||
this.con_GroupBox_1.TabIndex = 4;
|
this.con_GroupBox_1.TabIndex = 4;
|
||||||
this.con_GroupBox_1.TabStop = false;
|
this.con_GroupBox_1.TabStop = false;
|
||||||
this.con_GroupBox_1.Text = "Data log";
|
this.con_GroupBox_1.Text = "Data log";
|
||||||
@@ -357,7 +355,7 @@
|
|||||||
//
|
//
|
||||||
// con_Button_Quit
|
// con_Button_Quit
|
||||||
//
|
//
|
||||||
this.con_Button_Quit.Location = new System.Drawing.Point(580, 430);
|
this.con_Button_Quit.Location = new System.Drawing.Point(580, 441);
|
||||||
this.con_Button_Quit.Name = "con_Button_Quit";
|
this.con_Button_Quit.Name = "con_Button_Quit";
|
||||||
this.con_Button_Quit.Size = new System.Drawing.Size(86, 39);
|
this.con_Button_Quit.Size = new System.Drawing.Size(86, 39);
|
||||||
this.con_Button_Quit.TabIndex = 7;
|
this.con_Button_Quit.TabIndex = 7;
|
||||||
@@ -808,7 +806,7 @@
|
|||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(675, 479);
|
this.ClientSize = new System.Drawing.Size(675, 485);
|
||||||
this.Controls.Add(this.con_GroupBox_7);
|
this.Controls.Add(this.con_GroupBox_7);
|
||||||
this.Controls.Add(this.con_GroupBox_6);
|
this.Controls.Add(this.con_GroupBox_6);
|
||||||
this.Controls.Add(this.con_GroupBox_5);
|
this.Controls.Add(this.con_GroupBox_5);
|
||||||
@@ -932,7 +930,6 @@
|
|||||||
private System.Windows.Forms.Label label27;
|
private System.Windows.Forms.Label label27;
|
||||||
private System.Windows.Forms.Label label20;
|
private System.Windows.Forms.Label label20;
|
||||||
private System.Windows.Forms.Timer tim_HW_status;
|
private System.Windows.Forms.Timer tim_HW_status;
|
||||||
private System.Diagnostics.PerformanceCounter performanceCounter1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -425,9 +425,6 @@
|
|||||||
<metadata name="tim_HW_status.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
<metadata name="tim_HW_status.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
<value>800, 4</value>
|
<value>800, 4</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="performanceCounter1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
|
||||||
<value>800, 19</value>
|
|
||||||
</metadata>
|
|
||||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>26</value>
|
<value>26</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
|||||||
Reference in New Issue
Block a user