SystemTrayMenu/Utilities/Log.cs

61 lines
1.6 KiB
C#
Raw Normal View History

2020-03-17 02:45:19 +13:00
using Clearcove.Logging;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
namespace SystemTrayMenu.Helper
{
internal static class Log
{
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-17 09:05:52 +13:00
//internal static void Warn(string message)
//{
// log.Warn($"{message}{Environment.NewLine}" +
// $"{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()
{
Process.Start(GetLogFilePath());
}
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-17 02:45:19 +13:00
}
}