2020-03-17 02:45:19 +13:00
|
|
|
|
using Clearcove.Logging;
|
|
|
|
|
using System;
|
2020-03-30 06:26:45 +13:00
|
|
|
|
using System.ComponentModel;
|
2020-03-17 02:45:19 +13:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Reflection;
|
2020-03-30 06:26:45 +13:00
|
|
|
|
using System.Windows.Forms;
|
2020-03-17 02:45:19 +13:00
|
|
|
|
|
2020-03-28 12:42:32 +13:00
|
|
|
|
namespace SystemTrayMenu.Utilities
|
2020-03-17 02:45:19 +13:00
|
|
|
|
{
|
|
|
|
|
internal static class Log
|
|
|
|
|
{
|
2020-03-24 00:35:10 +13:00
|
|
|
|
private static readonly Logger log = new Logger("");
|
2020-03-17 02:45:19 +13:00
|
|
|
|
internal static void Initialize()
|
|
|
|
|
{
|
|
|
|
|
Logger.Start(new FileInfo(GetLogFilePath()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static void Info(string message)
|
|
|
|
|
{
|
|
|
|
|
log.Info(message);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 06:26:45 +13:00
|
|
|
|
internal static void Warn(string message, Exception ex)
|
|
|
|
|
{
|
2020-04-12 04:14:23 +12:00
|
|
|
|
log.Warn($"{message}{Environment.NewLine}{ex}");
|
2020-03-30 06:26:45 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//internal static void Debug(string message)
|
2020-03-17 09:05:52 +13:00
|
|
|
|
//{
|
2020-03-30 06:26:45 +13:00
|
|
|
|
// log.Debug($"{message}{Environment.NewLine}" +
|
2020-03-17 09:05:52 +13:00
|
|
|
|
// $"{Environment.StackTrace.ToString()}");
|
|
|
|
|
//}
|
|
|
|
|
|
2020-03-17 02:45:19 +13:00
|
|
|
|
internal static void Error(string message, Exception ex)
|
|
|
|
|
{
|
|
|
|
|
log.Error($"{message}{Environment.NewLine}" +
|
|
|
|
|
$"{ex.ToString()}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static string GetLogFilePath()
|
|
|
|
|
{
|
|
|
|
|
return Path.Combine(Path.GetDirectoryName(
|
|
|
|
|
Assembly.GetExecutingAssembly().Location),
|
|
|
|
|
$"log-{Environment.MachineName}.txt");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static void OpenLogFile()
|
|
|
|
|
{
|
2020-03-30 06:26:45 +13:00
|
|
|
|
ProcessStart(GetLogFilePath());
|
2020-03-17 02:45:19 +13:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-17 09:05:52 +13:00
|
|
|
|
internal static void WriteApplicationRuns()
|
2020-03-17 02:45:19 +13:00
|
|
|
|
{
|
|
|
|
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
|
|
|
|
log.Info($"Application Start " +
|
2020-03-17 03:57:51 +13:00
|
|
|
|
assembly.ManifestModule.Name + " | " +
|
|
|
|
|
assembly.GetName().Version.ToString() + " | " +
|
|
|
|
|
$"ScalingFactor={Scaling.Factor}");
|
2020-03-17 02:45:19 +13:00
|
|
|
|
}
|
2020-03-17 09:05:52 +13:00
|
|
|
|
|
|
|
|
|
internal static void Close()
|
|
|
|
|
{
|
|
|
|
|
Logger.ShutDown();
|
|
|
|
|
}
|
2020-03-30 06:26:45 +13:00
|
|
|
|
|
|
|
|
|
internal static void ProcessStart(string fileName, string arguments = null)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(arguments) &&
|
|
|
|
|
!Directory.Exists(arguments))
|
|
|
|
|
{
|
|
|
|
|
Exception ex = new DirectoryNotFoundException();
|
|
|
|
|
Warn($"path:'{arguments}'", ex);
|
|
|
|
|
MessageBox.Show(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//if (!string.IsNullOrEmpty(arguments))
|
|
|
|
|
//{
|
2020-03-30 06:59:43 +13:00
|
|
|
|
Process.Start(fileName, arguments);
|
2020-03-30 06:26:45 +13:00
|
|
|
|
//}
|
|
|
|
|
//else
|
|
|
|
|
//{
|
|
|
|
|
// Process.Start(fileName);
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
if (ex is FileNotFoundException ||
|
|
|
|
|
ex is Win32Exception)
|
|
|
|
|
{
|
|
|
|
|
Warn($"fileName:'{fileName}' arguments:'{arguments}'", ex);
|
|
|
|
|
MessageBox.Show(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-17 02:45:19 +13:00
|
|
|
|
}
|
|
|
|
|
}
|