mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-06-01 02:34:04 +02:00
Move logging to Reporter and make a static instance of it in Program
This commit is contained in:
parent
3176b6cb8f
commit
4c45d91d4e
25
Program.cs
25
Program.cs
@ -1,8 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using CefSharp;
|
using CefSharp;
|
||||||
using TweetDck.Configuration;
|
using TweetDck.Configuration;
|
||||||
@ -37,7 +35,7 @@ static class Program{
|
|||||||
public static readonly string TemporaryPath = IsPortable ? Path.Combine(ProgramPath, "portable", "tmp") : Path.Combine(Path.GetTempPath(), BrandName+'_'+Path.GetRandomFileName().Substring(0, 6));
|
public static readonly string TemporaryPath = IsPortable ? Path.Combine(ProgramPath, "portable", "tmp") : Path.Combine(Path.GetTempPath(), BrandName+'_'+Path.GetRandomFileName().Substring(0, 6));
|
||||||
|
|
||||||
public static readonly string ConfigFilePath = Path.Combine(StoragePath, "TD_UserConfig.cfg");
|
public static readonly string ConfigFilePath = Path.Combine(StoragePath, "TD_UserConfig.cfg");
|
||||||
public static readonly string LogFilePath = Path.Combine(ProgramPath, "td-log.txt");
|
private static readonly string LogFilePath = Path.Combine(ProgramPath, "td-log.txt");
|
||||||
|
|
||||||
public static readonly string ScriptPath = Path.Combine(ProgramPath, "scripts");
|
public static readonly string ScriptPath = Path.Combine(ProgramPath, "scripts");
|
||||||
public static readonly string PluginPath = Path.Combine(ProgramPath, "plugins");
|
public static readonly string PluginPath = Path.Combine(ProgramPath, "plugins");
|
||||||
@ -48,6 +46,7 @@ static class Program{
|
|||||||
private static bool HasCleanedUp;
|
private static bool HasCleanedUp;
|
||||||
|
|
||||||
public static UserConfig UserConfig { get; private set; }
|
public static UserConfig UserConfig { get; private set; }
|
||||||
|
public static Reporter Reporter { get; private set; }
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
private static void Main(){
|
private static void Main(){
|
||||||
@ -61,6 +60,8 @@ private static void Main(){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reporter = new Reporter(LogFilePath);
|
||||||
|
|
||||||
string[] programArguments = Environment.GetCommandLineArgs();
|
string[] programArguments = Environment.GetCommandLineArgs();
|
||||||
|
|
||||||
if (programArguments.Contains("-restart")){
|
if (programArguments.Contains("-restart")){
|
||||||
@ -183,22 +184,8 @@ public static void HandleException(string message, Exception e){ // TODO replace
|
|||||||
Reporter.HandleException(BrandName+" Has Failed :(", message, false, new Exception());
|
Reporter.HandleException(BrandName+" Has Failed :(", message, false, new Exception());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Log(string data){
|
public static void Log(string message){ // TODO replace all uses
|
||||||
StringBuilder build = new StringBuilder();
|
Reporter.Log(message);
|
||||||
|
|
||||||
if (!File.Exists(LogFilePath)){
|
|
||||||
build.Append("Please, report all issues to: https://github.com/chylex/TweetDuck/issues\r\n\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
build.Append("[").Append(DateTime.Now.ToString("G", CultureInfo.CurrentCulture)).Append("]\r\n");
|
|
||||||
build.Append(data).Append("\r\n\r\n");
|
|
||||||
|
|
||||||
try{
|
|
||||||
File.AppendAllText(LogFilePath, build.ToString(), Encoding.UTF8);
|
|
||||||
return true;
|
|
||||||
}catch{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ReloadConfig(){
|
public static void ReloadConfig(){
|
||||||
|
35
Reporter.cs
35
Reporter.cs
@ -1,13 +1,40 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using TweetDck.Core.Other;
|
using TweetDck.Core.Other;
|
||||||
|
|
||||||
namespace TweetDck{
|
namespace TweetDck{
|
||||||
static class Reporter{
|
class Reporter{
|
||||||
public static void HandleException(string caption, string message, bool canIgnore, Exception e){
|
private readonly string logFile;
|
||||||
Program.Log(e.ToString());
|
|
||||||
|
public Reporter(string logFile){
|
||||||
|
this.logFile = logFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Log(string data){
|
||||||
|
StringBuilder build = new StringBuilder();
|
||||||
|
|
||||||
|
if (!File.Exists(logFile)){
|
||||||
|
build.Append("Please, report all issues to: https://github.com/chylex/TweetDuck/issues\r\n\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
build.Append("[").Append(DateTime.Now.ToString("G", CultureInfo.CurrentCulture)).Append("]\r\n");
|
||||||
|
build.Append(data).Append("\r\n\r\n");
|
||||||
|
|
||||||
|
try{
|
||||||
|
File.AppendAllText(logFile, build.ToString(), Encoding.UTF8);
|
||||||
|
return true;
|
||||||
|
}catch{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void HandleException(string caption, string message, bool canIgnore, Exception e){
|
||||||
|
Log(e.ToString());
|
||||||
|
|
||||||
FormMessage form = new FormMessage(caption, message+"\r\nError: "+e.Message, canIgnore ? MessageBoxIcon.Warning : MessageBoxIcon.Error);
|
FormMessage form = new FormMessage(caption, message+"\r\nError: "+e.Message, canIgnore ? MessageBoxIcon.Warning : MessageBoxIcon.Error);
|
||||||
|
|
||||||
@ -23,7 +50,7 @@ public static void HandleException(string caption, string message, bool canIgnor
|
|||||||
UseVisualStyleBackColor = true
|
UseVisualStyleBackColor = true
|
||||||
};
|
};
|
||||||
|
|
||||||
btnOpenLog.Click += (sender, args) => Process.Start(Program.LogFilePath);
|
btnOpenLog.Click += (sender, args) => Process.Start(logFile);
|
||||||
|
|
||||||
form.AddActionControl(btnOpenLog);
|
form.AddActionControl(btnOpenLog);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user