fix logging

This commit is contained in:
Bitl 2021-11-13 13:56:56 -07:00
parent e3bfee0da4
commit 0468b36e4f
16 changed files with 129 additions and 70 deletions

View File

@ -1,4 +1,5 @@
#region Usings
using NLog;
using System;
using System.Diagnostics;
using System.IO;
@ -13,15 +14,23 @@ namespace Novetus.Bootstrapper
{
public static void LaunchApplicationExt(string filePath, string appName, string args = "")
{
Process client = new Process();
client.StartInfo.FileName = filePath + @"\\" + appName;
client.StartInfo.Arguments = args;
client.StartInfo.UseShellExecute = true;
if (SecurityFuncs.IsElevated)
GlobalFuncs.LogPrint("Starting " + appName);
try
{
client.StartInfo.Verb = "runas";
Process client = new Process();
client.StartInfo.FileName = filePath + @"\\" + appName;
client.StartInfo.Arguments = args;
client.StartInfo.UseShellExecute = true;
if (SecurityFuncs.IsElevated)
{
client.StartInfo.Verb = "runas";
}
client.Start();
}
catch (Exception ex)
{
GlobalFuncs.LogExceptions(ex);
}
client.Start();
}
public static void LaunchApplication(string appName, string args = "")

View File

@ -38,8 +38,15 @@
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.7.2\lib\net40-client\NLog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Transactions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
@ -74,6 +81,7 @@
<DesignTime>True</DesignTime>
</Compile>
<None Include="app.manifest" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

View File

@ -1,4 +1,5 @@
using System;
using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
@ -15,6 +16,12 @@ namespace Novetus.Bootstrapper
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var config = new NLog.Config.LoggingConfiguration();
var logfile = new NLog.Targets.FileTarget("logfile") { FileName = LocalPaths.FixedConfigDir + "\\Bootstrapper-log-" + DateTime.Today.ToString("MM-dd-yyyy") + ".log" };
config.AddRuleForAllLevels(logfile);
LogManager.Configuration = config;
Application.Run(new NovetusLaunchForm());
}
}

View File

@ -1,4 +1,5 @@
using System;
using NLog;
using System;
using System.Drawing;
using System.Drawing.Text;
using System.Windows.Forms;
@ -18,6 +19,7 @@ namespace Novetus.Bootstrapper
GlobalFuncs.ReadInfoFile(LocalPaths.InfoPath, true, LocalPaths.LauncherPath);
GlobalFuncs.LogPrint("Loading Font...");
try
{
PrivateFontCollection pfc = new PrivateFontCollection();
@ -29,9 +31,11 @@ namespace Novetus.Bootstrapper
VersionLabel.Font = new Font(fam, VersionLabel.Font.Size);
LaunchNovetusButton.Font = new Font(fam, VersionLabel.Font.Size);
}
GlobalFuncs.LogPrint("Font Loaded");
}
catch (Exception)
catch (Exception ex)
{
GlobalFuncs.LogExceptions(ex);
}
VersionLabel.Text = GlobalVars.ProgramInformation.Version.ToUpper();

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NLog" version="4.7.2" targetFramework="net40" />
</packages>

View File

@ -145,7 +145,7 @@ namespace NovetusCMD
var config = new NLog.Config.LoggingConfiguration();
var logfile = new NLog.Targets.FileTarget("logfile") { FileName = GlobalPaths.ConfigDir + "\\CMD-log-" + DateTime.Today.ToString("MM-dd-yyyy") + ".log" };
config.AddRule(LogLevel.Info, LogLevel.Fatal, logfile);
config.AddRuleForAllLevels(logfile);
LogManager.Configuration = config;
LoadCMDArgs(args);

View File

@ -57,7 +57,7 @@ public class INIFile
255, this.path);
return temp.ToString();
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
{
GlobalFuncs.LogExceptions(ex);

View File

@ -122,7 +122,7 @@ public class PartColorLoader
group.Header = group.Header + " (" + group.Items.Count + ")";
}*/
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
{
GlobalFuncs.LogExceptions(ex);
@ -146,7 +146,7 @@ public class PartColorLoader
return Bmp;
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
{
GlobalFuncs.LogExceptions(ex);

View File

@ -1,5 +1,5 @@
#region Usings
#if LAUNCHER || CMD || URI
#if LAUNCHER || CMD || URI || BASICLAUNCHER
using NLog;
#endif
using System;
@ -106,7 +106,7 @@ public class GlobalFuncs
GlobalVars.UserConfiguration.MapPath = GlobalPaths.MapsDir + @"\\" + GlobalVars.ProgramInformation.DefaultMap;
GlobalVars.UserConfiguration.MapPathSnip = GlobalPaths.MapsDirBase + @"\\" + GlobalVars.ProgramInformation.DefaultMap;
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
{
LogExceptions(ex);
@ -263,7 +263,7 @@ public class GlobalFuncs
Config(cfgpath, true);
}
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
{
LogExceptions(ex);
@ -419,7 +419,7 @@ public class GlobalFuncs
GlobalVars.UserCustomization.ExtraSelectionIsHat = Convert.ToBoolean(extraishat);
GlobalVars.UserCustomization.ShowHatsInExtra = Convert.ToBoolean(showhatsonextra);
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
{
LogExceptions(ex);
@ -542,7 +542,7 @@ public class GlobalFuncs
break;
}
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
{
LogExceptions(ex);
@ -572,7 +572,7 @@ public class GlobalFuncs
goto Failure;
}
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
{
LogExceptions(ex);
@ -610,7 +610,7 @@ public class GlobalFuncs
goto Failure;
}
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
{
LogExceptions(ex);
@ -676,7 +676,7 @@ public class GlobalFuncs
ReadClientValues(name, initial);
#endif
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
{
LogExceptions(ex);
@ -938,7 +938,7 @@ public class GlobalFuncs
image.SetPropertyItem(item);
}
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
{
LogExceptions(ex);
@ -972,7 +972,7 @@ public class GlobalFuncs
LoadClientValues(info, clientpath);
return info;
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
{
LogExceptions(ex);
@ -1505,7 +1505,7 @@ public class GlobalFuncs
}
}
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
{
LogExceptions(ex);
@ -1571,7 +1571,7 @@ public class GlobalFuncs
ApplyClientSettings(info, ClientName, GraphicsMode, MeshDetail, ShadingQuality, MaterialQuality,
AA, AASamples, Bevels, Shadows_2008, Shadows_2007, Style_2007, GFXQualityLevel, WindowResolution, FullscreenResolution, ModernResolution);
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
{
LogExceptions(ex);
@ -1610,7 +1610,7 @@ public class GlobalFuncs
fixedfile = RobloxXML.RemoveInvalidXmlChars(RobloxXML.ReplaceHexadecimalSymbols(oldfile));
doc = XDocument.Parse(fixedfile);
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
{
LogExceptions(ex);
@ -1660,7 +1660,7 @@ public class GlobalFuncs
RobloxXML.EditRenderSettings(doc, "Resolution", ModernResolution.ToString(), XMLTypes.Token);
}
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
{
LogExceptions(ex);
@ -1680,7 +1680,7 @@ public class GlobalFuncs
}
}
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
{
LogExceptions(ex);
@ -1956,7 +1956,7 @@ public class GlobalFuncs
GlobalVars.ValidatedExtraFiles += 1;
}
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
{
LogExceptions(ex);
@ -2097,7 +2097,7 @@ public class GlobalFuncs
GlobalVars.ValidatedExtraFiles = 0;
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
#else
catch (Exception)
@ -2120,7 +2120,7 @@ public class GlobalFuncs
#if URI || LAUNCHER
MessageBox.Show("Failed to launch Novetus. (Error: " + ex.Message + ")", "Novetus - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
LogExceptions(ex);
#endif
}
@ -2184,40 +2184,38 @@ public class GlobalFuncs
box.AppendText("[" + DateTime.Now.ToShortTimeString() + "] - ", Color.White);
Logger log = LogManager.GetCurrentClassLogger();
switch (type)
{
case 2:
box.AppendText(text, Color.Red);
if (!noLog)
log.Error(text);
LogPrint(text, 2);
break;
case 3:
box.AppendText(text, Color.Lime);
if (!noLog)
log.Info(text);
LogPrint(text);
break;
case 4:
box.AppendText(text, Color.Aqua);
if (!noLog)
log.Info(text);
LogPrint(text);
break;
case 5:
box.AppendText(text, Color.Yellow);
if (!noLog)
log.Warn(text);
LogPrint(text, 3);
break;
case 6:
box.AppendText(text, Color.LightSalmon);
if (!noLog)
log.Info(text);
LogPrint(text);
break;
case 1:
default:
box.AppendText(text, Color.White);
if (!noLog)
log.Info(text);
LogPrint(text);
break;
}
@ -2231,30 +2229,28 @@ public class GlobalFuncs
ConsoleText("[" + DateTime.Now.ToShortTimeString() + "] - ", ConsoleColor.White);
}
Logger log = LogManager.GetCurrentClassLogger();
switch (type)
{
case 2:
ConsoleText(text, ConsoleColor.Red);
log.Error(text);
LogPrint(text, 2);
break;
case 3:
ConsoleText(text, ConsoleColor.Green);
log.Info(text);
LogPrint(text);
break;
case 4:
ConsoleText(text, ConsoleColor.Cyan);
log.Info(text);
LogPrint(text);
break;
case 5:
ConsoleText(text, ConsoleColor.Yellow);
log.Warn(text);
LogPrint(text, 3);
break;
case 1:
default:
ConsoleText(text, ConsoleColor.White);
log.Info(text);
LogPrint(text);
break;
}
@ -2308,6 +2304,24 @@ public class GlobalFuncs
}
#endif
public static void LogPrint(string text, int type = 1)
{
Logger log = LogManager.GetCurrentClassLogger();
switch (type)
{
case 2:
log.Error(text);
break;
case 3:
log.Warn(text);
break;
default:
log.Info(text);
break;
}
}
public static void CreateAssetCacheDirectories()
{
if (!Directory.Exists(GlobalPaths.AssetCacheDirFonts))
@ -2417,7 +2431,7 @@ public class GlobalFuncs
}
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
{
LogExceptions(ex);
@ -2460,7 +2474,7 @@ public class GlobalFuncs
FixedFileMove(path, finalPath, File.Exists(finalPath));
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
{
LogExceptions(ex);
@ -2471,13 +2485,12 @@ public class GlobalFuncs
}
}
#if LAUNCHER || CMD || URI
#if LAUNCHER || CMD || URI || BASICLAUNCHER
public static void LogExceptions(Exception ex)
{
Logger log = LogManager.GetCurrentClassLogger();
log.Error("EXCEPTION|MESSAGE: " + (ex.Message != null ? ex.Message.ToString() : "N/A"));
log.Error("EXCEPTION|STACK TRACE: " + (!string.IsNullOrWhiteSpace(ex.StackTrace) ? ex.StackTrace : "N/A"));
log.Error("EXCEPTION|ADDITIONAL INFO: " + (ex != null ? ex.ToString() : "N/A"));
LogPrint("EXCEPTION|MESSAGE: " + (ex.Message != null ? ex.Message.ToString() : "N/A"), 2);
LogPrint("EXCEPTION|STACK TRACE: " + (!string.IsNullOrWhiteSpace(ex.StackTrace) ? ex.StackTrace : "N/A"), 2);
LogPrint("EXCEPTION|ADDITIONAL INFO: " + (ex != null ? ex.ToString() : "N/A"), 2);
}
#endif
@ -2542,7 +2555,7 @@ public class GlobalFuncs
}
catch (Exception ex)
{
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
LogExceptions(ex);
#endif
return "ERROR: " + ex.Message;

View File

@ -143,7 +143,7 @@ public class ScriptFuncs
string result = code.Substring(pFrom, pTo - pFrom);
return result;
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
{
GlobalFuncs.LogExceptions(ex);
@ -221,7 +221,7 @@ public class ScriptFuncs
return source;
}
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
{
GlobalFuncs.LogExceptions(ex);

View File

@ -258,7 +258,7 @@ public class SecurityFuncs
{
ipAddress = new WebClient().DownloadString("https://ipv4.icanhazip.com/").TrimEnd();
}
#if URI || LAUNCHER || CMD
#if URI || LAUNCHER || CMD || BASICLAUNCHER
catch (Exception ex)
{
GlobalFuncs.LogExceptions(ex);

View File

@ -19,7 +19,7 @@ namespace NovetusLauncher
var config = new NLog.Config.LoggingConfiguration();
var logfile = new NLog.Targets.FileTarget("logfile") { FileName = GlobalPaths.ConfigDir + "\\Launcher-log-" + DateTime.Today.ToString("MM-dd-yyyy") + ".log" };
config.AddRule(LogLevel.Info, LogLevel.Fatal, logfile);
config.AddRuleForAllLevels(logfile);
LogManager.Configuration = config;
GlobalFuncs.ReadInfoFile(GlobalPaths.ConfigDir + "\\" + GlobalPaths.InfoName);

View File

@ -32,6 +32,7 @@ namespace NovetusURI
}
else
{
GlobalFuncs.LogPrint("Failed to register. (Error: Did not run as Administrator)", 2);
MessageBox.Show("Failed to register. (Error: Did not run as Administrator)", "Novetus - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
form.Close();
}
@ -78,16 +79,23 @@ namespace NovetusURI
public static void SetupURIValues()
{
string ExtractedArg = LocalVars.SharedArgs.Replace("novetus://", "").Replace("novetus", "").Replace(":", "").Replace("/", "").Replace("?", "");
string ConvertedArg = SecurityFuncs.Base64DecodeOld(ExtractedArg);
string[] SplitArg = ConvertedArg.Split('|');
string ip = SecurityFuncs.Base64Decode(SplitArg[0]);
string port = SecurityFuncs.Base64Decode(SplitArg[1]);
string client = SecurityFuncs.Base64Decode(SplitArg[2]);
GlobalVars.UserConfiguration.SelectedClient = client;
GlobalVars.IP = ip;
GlobalVars.JoinPort = Convert.ToInt32(port);
GlobalFuncs.ReadClientValues();
try
{
string ExtractedArg = LocalVars.SharedArgs.Replace("novetus://", "").Replace("novetus", "").Replace(":", "").Replace("/", "").Replace("?", "");
string ConvertedArg = SecurityFuncs.Base64DecodeOld(ExtractedArg);
string[] SplitArg = ConvertedArg.Split('|');
string ip = SecurityFuncs.Base64Decode(SplitArg[0]);
string port = SecurityFuncs.Base64Decode(SplitArg[1]);
string client = SecurityFuncs.Base64Decode(SplitArg[2]);
GlobalVars.UserConfiguration.SelectedClient = client;
GlobalVars.IP = ip;
GlobalVars.JoinPort = Convert.ToInt32(port);
GlobalFuncs.ReadClientValues();
}
catch (Exception ex)
{
GlobalFuncs.LogExceptions(ex);
}
}
}
#endregion

View File

@ -25,6 +25,7 @@ namespace NovetusURI
private void button1_Click(object sender, EventArgs e)
{
GlobalFuncs.LogPrint("Attempting to install URI.");
LocalFuncs.RegisterURI(this);
Close();
}

View File

@ -4,6 +4,7 @@ using System.IO;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;
using NLog;
#endregion
namespace NovetusURI
@ -68,6 +69,7 @@ namespace NovetusURI
#region Form Events
void LoaderFormLoad(object sender, EventArgs e)
{
GlobalFuncs.LogPrint("Booting Quick Configure....");
QuickConfigure main = new QuickConfigure();
main.ShowDialog();
System.Threading.Timer timer = new System.Threading.Timer(new TimerCallback(CheckIfFinished), null, 1, 0);
@ -97,13 +99,16 @@ namespace NovetusURI
}
else
{
GlobalFuncs.LogPrint("Ready to launch.");
Visible = true;
CenterToScreen();
if (GlobalVars.UserConfiguration.DiscordPresence)
{
GlobalFuncs.LogPrint("Starting Discord Rich Presence...");
label1.Text = "Starting Discord Rich Presence...";
StartDiscord();
}
GlobalFuncs.LogPrint("Launching Game...");
label1.Text = "Launching Game...";
LocalFuncs.SetupURIValues();
StartGame();

View File

@ -22,7 +22,7 @@ namespace NovetusURI
var config = new NLog.Config.LoggingConfiguration();
var logfile = new NLog.Targets.FileTarget("logfile") { FileName = GlobalPaths.ConfigDir + "\\URI-log-" + DateTime.Today.ToString("MM-dd-yyyy") + ".log" };
config.AddRule(LogLevel.Info, LogLevel.Fatal, logfile);
config.AddRuleForAllLevels(logfile);
LogManager.Configuration = config;
GlobalFuncs.ReadInfoFile(GlobalPaths.ConfigDir + "\\" + GlobalPaths.InfoName);