mirror of
https://github.com/DaKerboul/perun.git
synced 2026-08-09 19:05:39 +02:00
Added a "log level" and a "close to tray" settings for the Windows application
This commit is contained in:
@@ -180,36 +180,36 @@ public class DatabaseController
|
||||
switch (Int32.Parse(TCPFrameType))
|
||||
{
|
||||
case 1:
|
||||
PerunHelper.AddLog(ref Globals.AppLogHistory, "Connected players: " + TCPFrame.payload["c_players"], 1,0,"1");
|
||||
PerunHelper.LogDebug(ref Globals.AppLogHistory, "Connected players: " + TCPFrame.payload["c_players"], 1,0,"1");
|
||||
break;
|
||||
case 2:
|
||||
PerunHelper.AddLog(ref Globals.AppLogHistory, "Mission: \"" + TCPFrame.payload["mission"]["name"]+"\""+ ", time:" + TCPFrame.payload["mission"]["modeltime"], 1, 0, "2");
|
||||
PerunHelper.LogDebug(ref Globals.AppLogHistory, "Mission: \"" + TCPFrame.payload["mission"]["name"]+"\""+ ", time:" + TCPFrame.payload["mission"]["modeltime"], 1, 0, "2");
|
||||
break;
|
||||
case 3:
|
||||
PerunHelper.AddLog(ref Globals.AppLogHistory, "Slots data updated", 1, 0, "3");
|
||||
PerunHelper.LogDebug(ref Globals.AppLogHistory, "Slots data updated", 1, 0, "3");
|
||||
break;
|
||||
case 50:
|
||||
PerunHelper.AddLog(ref Globals.AppLogHistory, "Player's \""+ TCPFrame.payload.player + "\" chat message saved", 1, 0, "50");
|
||||
PerunHelper.LogDebug(ref Globals.AppLogHistory, "Player's \""+ TCPFrame.payload.player + "\" chat message saved", 1, 0, "50");
|
||||
break;
|
||||
case 51:
|
||||
PerunHelper.AddLog(ref Globals.AppLogHistory, "Game event: \""+ TCPFrame.payload.log_content +"\"", 1, 0, "51");
|
||||
PerunHelper.LogDebug(ref Globals.AppLogHistory, "Game event: \""+ TCPFrame.payload.log_content +"\"", 1, 0, "51");
|
||||
break;
|
||||
case 52:
|
||||
PerunHelper.AddLog(ref Globals.AppLogHistory, "Player's \""+ TCPFrame.payload.stat_name + "\" stats saved", 1, 0, "52");
|
||||
PerunHelper.LogDebug(ref Globals.AppLogHistory, "Player's \""+ TCPFrame.payload.stat_name + "\" stats saved", 1, 0, "52");
|
||||
break;
|
||||
case 53:
|
||||
PerunHelper.AddLog(ref Globals.AppLogHistory, "Player \""+ TCPFrame.payload.login_name + "\" logged in", 1, 0, "53");
|
||||
PerunHelper.LogDebug(ref Globals.AppLogHistory, "Player \""+ TCPFrame.payload.login_name + "\" logged in", 1, 0, "53");
|
||||
break;
|
||||
case 100:
|
||||
PerunHelper.AddLog(ref Globals.AppLogHistory, "SRS data send", 1,0,"100");
|
||||
PerunHelper.LogDebug(ref Globals.AppLogHistory, "SRS data send", 1,0,"100");
|
||||
break;
|
||||
case 101:
|
||||
PerunHelper.AddLog(ref Globals.AppLogHistory, "LotATC data send", 1,0,"101");
|
||||
PerunHelper.LogDebug(ref Globals.AppLogHistory, "LotATC data send", 1,0,"101");
|
||||
break;
|
||||
case -1:
|
||||
break;
|
||||
default:
|
||||
PerunHelper.AddLog(ref Globals.AppLogHistory, "Data send", 1,0, TCPFrameType);
|
||||
PerunHelper.LogDebug(ref Globals.AppLogHistory, "Data send", 1,0, TCPFrameType);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ public class DatabaseController
|
||||
{
|
||||
// General exception found
|
||||
Console.WriteLine(a_ex.ToString());
|
||||
PerunHelper.AddLog(ref Globals.AppLogHistory, "ERROR MySQL - error: " + a_ex.Message,1,1, TCPFrameType);
|
||||
PerunHelper.LogError(ref Globals.AppLogHistory, "ERROR MySQL - error: " + a_ex.Message,1,1, TCPFrameType);
|
||||
Globals.ErrorsGame++;
|
||||
DatabaseStatus = false;
|
||||
ReturnValue = 0;
|
||||
@@ -229,25 +229,25 @@ public class DatabaseController
|
||||
switch (m_ex.Number)
|
||||
{
|
||||
case 1042: // Unable to connect to any of the specified MySQL hosts (Check Server,Port)
|
||||
PerunHelper.AddLog(ref Globals.AppLogHistory, "ERROR MySQL - unable to connect, error: " + m_ex.Message,1,1, TCPFrameType);
|
||||
PerunHelper.LogError(ref Globals.AppLogHistory, "ERROR MySQL - unable to connect, error: " + m_ex.Message,1,1, TCPFrameType);
|
||||
DatabaseStatus = false;
|
||||
ReturnValue = 0;
|
||||
break;
|
||||
case 0: // Access denied (Check DB name,username,password)
|
||||
PerunHelper.AddLog(ref Globals.AppLogHistory, "ERROR MySQL - access denied, error: " + m_ex.Message,1,1, TCPFrameType);
|
||||
PerunHelper.LogError(ref Globals.AppLogHistory, "ERROR MySQL - access denied, error: " + m_ex.Message,1,1, TCPFrameType);
|
||||
DatabaseStatus = false;
|
||||
ReturnValue = 0;
|
||||
break;
|
||||
case 1064: // Incorrect query
|
||||
PerunHelper.AddLog(ref Globals.AppLogHistory, "ERROR MySQL - query: " + SQLQueryTxt, 1, 1, TCPFrameType);
|
||||
PerunHelper.AddLog(ref Globals.AppLogHistory, "ERROR MySQL - error: " + m_ex.Message, 1, 1, TCPFrameType);
|
||||
PerunHelper.LogError(ref Globals.AppLogHistory, "ERROR MySQL - query: " + SQLQueryTxt, 1, 1, TCPFrameType);
|
||||
PerunHelper.LogError(ref Globals.AppLogHistory, "ERROR MySQL - error: " + m_ex.Message, 1, 1, TCPFrameType);
|
||||
DatabaseStatus = true; // True as connection is not broken
|
||||
ReturnValue = 1; // Return a value to remove this query from quae
|
||||
break;
|
||||
default:
|
||||
PerunHelper.AddLog(ref Globals.AppLogHistory, "ERROR MySQL - error id: " + m_ex.Number,1,1, TCPFrameType);
|
||||
PerunHelper.AddLog(ref Globals.AppLogHistory, "ERROR MySQL - query: " + SQLQueryTxt, 1, 1, TCPFrameType);
|
||||
PerunHelper.AddLog(ref Globals.AppLogHistory, "ERROR MySQL - error: " + m_ex.Message,1,1, TCPFrameType);
|
||||
PerunHelper.LogError(ref Globals.AppLogHistory, "ERROR MySQL - error id: " + m_ex.Number,1,1, TCPFrameType);
|
||||
PerunHelper.LogError(ref Globals.AppLogHistory, "ERROR MySQL - query: " + SQLQueryTxt, 1, 1, TCPFrameType);
|
||||
PerunHelper.LogError(ref Globals.AppLogHistory, "ERROR MySQL - error: " + m_ex.Message,1,1, TCPFrameType);
|
||||
DatabaseStatus = false;
|
||||
ReturnValue = 0;
|
||||
break;
|
||||
@@ -260,7 +260,7 @@ public class DatabaseController
|
||||
}
|
||||
catch (ArgumentException x_ex)
|
||||
{
|
||||
PerunHelper.AddLog(ref Globals.AppLogHistory, "ERROR MySQL - unable to connect, error: " + x_ex.Message,1,1, TCPFrameType);
|
||||
PerunHelper.LogError(ref Globals.AppLogHistory, "ERROR MySQL - unable to connect, error: " + x_ex.Message,1,1, TCPFrameType);
|
||||
ReturnValue = 0;
|
||||
Globals.ErrorsGame++;
|
||||
}
|
||||
|
||||
@@ -3,9 +3,47 @@ using System.IO;
|
||||
|
||||
class LogController
|
||||
{
|
||||
// TBD - done via https://stackoverflow.com/questions/20185015/how-to-write-log-file-in-c
|
||||
public static void WriteLog(string strLog)
|
||||
private static LogController _instance = new LogController();
|
||||
|
||||
public static LogController instance
|
||||
{
|
||||
get
|
||||
{
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
public int level
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public void LogError(string strLog)
|
||||
{
|
||||
this.WriteLog(0, strLog);
|
||||
}
|
||||
|
||||
public void LogWarning(string strLog)
|
||||
{
|
||||
this.WriteLog(1, strLog);
|
||||
}
|
||||
|
||||
public void LogInfo(string strLog)
|
||||
{
|
||||
this.WriteLog(2, strLog);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (logLevel > this.level) return;
|
||||
|
||||
StreamWriter LogStreamWriter;
|
||||
FileStream LogFileStream = null;
|
||||
DirectoryInfo LogDirectoryInfo = null;
|
||||
|
||||
@@ -5,7 +5,27 @@ using System.Text.RegularExpressions;
|
||||
|
||||
internal class PerunHelper
|
||||
{
|
||||
public static void AddLog(ref string[] arrLogHistory, string strEntryToAdd, int intDirection = 0, int intMarker = 0, string strType = " ", bool bSkipGui = false)
|
||||
public static void LogError(ref string[] arrLogHistory, string strEntryToAdd, int intDirection = 0, int intMarker = 0, string strType = " ", bool bSkipGui = false)
|
||||
{
|
||||
AddLog(0, ref arrLogHistory, strEntryToAdd, intDirection, intMarker, strType, bSkipGui);
|
||||
}
|
||||
|
||||
public static void LogWarning(ref string[] arrLogHistory, string strEntryToAdd, int intDirection = 0, int intMarker = 0, string strType = " ", bool bSkipGui = false)
|
||||
{
|
||||
AddLog(1, ref arrLogHistory, strEntryToAdd, intDirection, intMarker, strType, bSkipGui);
|
||||
}
|
||||
|
||||
public static void LogInfo(ref string[] arrLogHistory, string strEntryToAdd, int intDirection = 0, int intMarker = 0, string strType = " ", bool bSkipGui = false)
|
||||
{
|
||||
AddLog(2, ref arrLogHistory, strEntryToAdd, intDirection, intMarker, strType, bSkipGui);
|
||||
}
|
||||
|
||||
public static void LogDebug(ref string[] arrLogHistory, string strEntryToAdd, int intDirection = 0, int intMarker = 0, string strType = " ", bool bSkipGui = false)
|
||||
{
|
||||
AddLog(3, ref arrLogHistory, strEntryToAdd, intDirection, intMarker, strType, bSkipGui);
|
||||
}
|
||||
|
||||
private static void AddLog(int logLevel, ref string[] arrLogHistory, string strEntryToAdd, int intDirection = 0, int intMarker = 0, string strType = " ", bool bSkipGui = false)
|
||||
{
|
||||
// Declare values
|
||||
string LogDirection;
|
||||
@@ -48,7 +68,7 @@ internal class PerunHelper
|
||||
Globals.AppUpdateGUI = true;
|
||||
}
|
||||
// Add the entry to log file
|
||||
LogController.WriteLog(DateTime.Now.ToString("yyyy-MM-dd ") + " " + DateTime.Now.ToString("HH:mm:ss") + " | Instance: "+ Globals.AppInstanceID + " | " + LogMarker + " | "+ LogDirection + " | "+ strType + " | " + strEntryToAdd);
|
||||
LogController.instance.WriteLog(logLevel, DateTime.Now.ToString("yyyy-MM-dd ") + " " + DateTime.Now.ToString("HH:mm:ss") + " | Instance: "+ Globals.AppInstanceID + " | " + LogMarker + " | "+ LogDirection + " | "+ strType + " | " + strEntryToAdd);
|
||||
}
|
||||
|
||||
public static string GetAppVersion(string strBeginning)
|
||||
@@ -72,7 +92,7 @@ internal class PerunHelper
|
||||
if(VersionApp != Globals.VersionDatabase)
|
||||
{
|
||||
// Incorrect database version
|
||||
PerunHelper.AddLog(ref Globals.AppLogHistory, "ERROR Incorrect database revision : "+ Globals.VersionDatabase, 1, 1, "?");
|
||||
PerunHelper.LogError(ref Globals.AppLogHistory, "ERROR Incorrect database revision : "+ Globals.VersionDatabase, 1, 1, "?");
|
||||
Globals.ErrorsDatabase++;
|
||||
ReturnValue = 0;
|
||||
}
|
||||
@@ -84,7 +104,7 @@ internal class PerunHelper
|
||||
if (VersionApp != Globals.VersionDCSHook)
|
||||
{
|
||||
// Incorrect dcs script version
|
||||
PerunHelper.AddLog(ref Globals.AppLogHistory, "ERROR Incorrect DCS hook revision : " + Globals.VersionDCSHook, 2, 1, "?");
|
||||
PerunHelper.LogError(ref Globals.AppLogHistory, "ERROR Incorrect DCS hook revision : " + Globals.VersionDCSHook, 2, 1, "?");
|
||||
Globals.ErrorsGame++;
|
||||
ReturnValue = 0;
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ public class TCPController
|
||||
if (Int32.Parse(strRawTCPFrameType) != 0)
|
||||
{
|
||||
// Add to mySQL send buffer (find first empty slot)
|
||||
PerunHelper.AddLog(ref arrGUILogHistory, "Packet received" , 2,0, strRawTCPFrameType,true);
|
||||
PerunHelper.LogDebug(ref arrGUILogHistory, "Packet received" , 2,0, strRawTCPFrameType,true);
|
||||
bool AddedDataToBuffer = false;
|
||||
for (int i = 0; i < arrMySQLSendBuffer.Length - 1; i++)
|
||||
{
|
||||
@@ -139,12 +139,12 @@ public class TCPController
|
||||
}
|
||||
if (!AddedDataToBuffer)
|
||||
{
|
||||
PerunHelper.AddLog(ref arrGUILogHistory, "ERROR package was dropped", 1, 1, strRawTCPFrameType);
|
||||
PerunHelper.LogError(ref arrGUILogHistory, "ERROR package was dropped", 1, 1, strRawTCPFrameType);
|
||||
}
|
||||
} else
|
||||
{
|
||||
// Keep alive
|
||||
PerunHelper.AddLog(ref arrGUILogHistory, "Keep-alive received", 2,0,"0",true);
|
||||
PerunHelper.LogDebug(ref arrGUILogHistory, "Keep-alive received", 2,0,"0",true);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -156,7 +156,7 @@ public class TCPController
|
||||
{
|
||||
Globals.ErrorsGame++;
|
||||
Console.WriteLine(e.ToString());
|
||||
PerunHelper.AddLog(ref arrGUILogHistory, "ERROR while message parsing , error: " + e.Message,2,1,"?");
|
||||
PerunHelper.LogError(ref arrGUILogHistory, "ERROR while message parsing , error: " + e.Message,2,1,"?");
|
||||
bTCPConnectionOnline = false;
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ public class TCPController
|
||||
catch (SocketException e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
PerunHelper.AddLog(ref arrGUILogHistory, "TCP ERROR cannot check connection, error: " + e.Message,2,1,"?");
|
||||
PerunHelper.LogError(ref arrGUILogHistory, "TCP ERROR cannot check connection, error: " + e.Message,2,1,"?");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -182,7 +182,7 @@ public class TCPController
|
||||
{
|
||||
Globals.ErrorsGame++;
|
||||
Console.WriteLine(e.ToString());
|
||||
PerunHelper.AddLog(ref arrGUILogHistory, "TCP error - connection closed or port in use, error: " + e.Message,1,1,"?");
|
||||
PerunHelper.LogError(ref arrGUILogHistory, "TCP error - connection closed or port in use, error: " + e.Message,1,1,"?");
|
||||
bTCPConnectionOnline = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user