- Fix logging issues

This commit is contained in:
Stone_Red
2021-12-23 10:20:58 +01:00
parent 668c393a1b
commit f62ea316a1
2 changed files with 17 additions and 11 deletions
+12 -6
View File
@@ -30,19 +30,21 @@ public partial class App : Application
public App() public App()
{ {
logFilePath = ApplicationDataPath + "\\Log.log"; logFilePath = ApplicationDataPath + "\\Log.log";
Setup();
// Try to grab mutex // Try to grab mutex
_mutex = new Mutex(true, $"Stone_Red{AppName}", out bool createdNew); _mutex = new Mutex(true, $"Stone_Red{AppName}", out bool createdNew);
//check if creating new was successful //check if creating new was successful
if (!createdNew) if (!createdNew)
{ {
Setup(false);
Logger.Log("Shutting down because other instance already running.", "Setup"); Logger.Log("Shutting down because other instance already running.", "Setup");
//Shutdown Application //Shutdown Application
Current.Shutdown(); Current.Shutdown();
} }
else else
{ {
Setup(true);
Exit += CloseMutexHandler; Exit += CloseMutexHandler;
updater.ProgressChanged += Updater_ProgressChanged; updater.ProgressChanged += Updater_ProgressChanged;
@@ -60,7 +62,7 @@ public partial class App : Application
private void Updater_NoUpdateAvailible() private void Updater_NoUpdateAvailible()
{ {
Logger.Log("No update available.", "Updater"); Logger.Log("No update available", "Updater");
} }
private void Updater_OnException(Exception exception) private void Updater_OnException(Exception exception)
@@ -70,7 +72,7 @@ public partial class App : Application
private void Updater_ProgressChanged(long? totalFileSize, long totalBytesDownloaded, double? progressPercentage) private void Updater_ProgressChanged(long? totalFileSize, long totalBytesDownloaded, double? progressPercentage)
{ {
Logger.Log($"{progressPercentage}% {totalBytesDownloaded}/{totalFileSize}", "Updater"); Logger.Log($"Downloading: {progressPercentage}% {totalBytesDownloaded}/{totalFileSize}", "Updater");
} }
protected void CloseMutexHandler(object sender, EventArgs e) protected void CloseMutexHandler(object sender, EventArgs e)
@@ -78,7 +80,7 @@ public partial class App : Application
_mutex?.Close(); _mutex?.Close();
} }
private void Setup() private void Setup(bool clearLogFile)
{ {
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
@@ -129,12 +131,16 @@ public partial class App : Application
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Log(ex.Message, "Setup", LogSeverity.Error);
_ = MessageBox.Show(ex.ToString()); _ = MessageBox.Show(ex.ToString());
Logger.Log(ex.Message, "Setup", LogSeverity.Error);
} }
if (clearLogFile)
{
Logger.ClearLogFile(LogSeverity.Info); Logger.ClearLogFile(LogSeverity.Info);
Logger.Log("Log setup complete.", "Setup"); }
Logger.Log("Log setup complete", "Setup");
} }
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
+3 -3
View File
@@ -7,11 +7,11 @@
<ApplicationIcon>icon.ico</ApplicationIcon> <ApplicationIcon>icon.ico</ApplicationIcon>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent> <RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
<Authors>Stone_Red</Authors> <Authors>Stone_Red</Authors>
<Version>0.0.3.1</Version> <Version>0.0.3.2</Version>
<PackageProjectUrl>https://github.com/Stone-Red-Code/DesktopMagic</PackageProjectUrl> <PackageProjectUrl>https://github.com/Stone-Red-Code/DesktopMagic</PackageProjectUrl>
<RepositoryUrl>https://github.com/Stone-Red-Code/DesktopMagic</RepositoryUrl> <RepositoryUrl>https://github.com/Stone-Red-Code/DesktopMagic</RepositoryUrl>
<AssemblyVersion>0.0.3.1</AssemblyVersion> <AssemblyVersion>0.0.3.2</AssemblyVersion>
<FileVersion>0.0.3.1</FileVersion> <FileVersion>0.0.3.2</FileVersion>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net6.0-windows</TargetFramework>
</PropertyGroup> </PropertyGroup>