mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-31 08:34:10 +02:00
Add IAppErrorHandler w/ implementation
This commit is contained in:
parent
da706d7ed8
commit
77030c9b23
@ -58,6 +58,7 @@ static Program(){
|
|||||||
Config = new ConfigManager();
|
Config = new ConfigManager();
|
||||||
|
|
||||||
Lib.Initialize(new App.Builder{
|
Lib.Initialize(new App.Builder{
|
||||||
|
ErrorHandler = Reporter
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
11
Reporter.cs
11
Reporter.cs
@ -7,9 +7,10 @@
|
|||||||
using TweetDuck.Configuration;
|
using TweetDuck.Configuration;
|
||||||
using TweetDuck.Core.Other;
|
using TweetDuck.Core.Other;
|
||||||
using TweetLib.Core;
|
using TweetLib.Core;
|
||||||
|
using TweetLib.Core.Application;
|
||||||
|
|
||||||
namespace TweetDuck{
|
namespace TweetDuck{
|
||||||
sealed class Reporter{
|
sealed class Reporter : IAppErrorHandler{
|
||||||
private readonly string logFile;
|
private readonly string logFile;
|
||||||
|
|
||||||
public Reporter(string logFile){
|
public Reporter(string logFile){
|
||||||
@ -29,8 +30,12 @@ public bool LogVerbose(string data){
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bool LogImportant(string data){
|
public bool LogImportant(string data){
|
||||||
|
return ((IAppErrorHandler)this).Log(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IAppErrorHandler.Log(string text){
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
Debug.WriteLine(data);
|
Debug.WriteLine(text);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
StringBuilder build = new StringBuilder();
|
StringBuilder build = new StringBuilder();
|
||||||
@ -40,7 +45,7 @@ public bool LogImportant(string data){
|
|||||||
}
|
}
|
||||||
|
|
||||||
build.Append("[").Append(DateTime.Now.ToString("G", Lib.Culture)).Append("]\r\n");
|
build.Append("[").Append(DateTime.Now.ToString("G", Lib.Culture)).Append("]\r\n");
|
||||||
build.Append(data).Append("\r\n\r\n");
|
build.Append(text).Append("\r\n\r\n");
|
||||||
|
|
||||||
try{
|
try{
|
||||||
File.AppendAllText(logFile, build.ToString(), Encoding.UTF8);
|
File.AppendAllText(logFile, build.ToString(), Encoding.UTF8);
|
||||||
|
@ -3,14 +3,17 @@
|
|||||||
|
|
||||||
namespace TweetLib.Core{
|
namespace TweetLib.Core{
|
||||||
public sealed class App{
|
public sealed class App{
|
||||||
|
public static IAppErrorHandler ErrorHandler { get; private set; }
|
||||||
|
|
||||||
// Builder
|
// Builder
|
||||||
|
|
||||||
public sealed class Builder{
|
public sealed class Builder{
|
||||||
|
public IAppErrorHandler? ErrorHandler { get; set; }
|
||||||
|
|
||||||
// Validation
|
// Validation
|
||||||
|
|
||||||
internal void Initialize(){
|
internal void Initialize(){
|
||||||
|
App.ErrorHandler = Validate(ErrorHandler, nameof(ErrorHandler))!;
|
||||||
}
|
}
|
||||||
|
|
||||||
private T Validate<T>(T obj, string name){
|
private T Validate<T>(T obj, string name){
|
||||||
|
8
lib/TweetLib.Core/Application/IAppErrorHandler.cs
Normal file
8
lib/TweetLib.Core/Application/IAppErrorHandler.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace TweetLib.Core.Application{
|
||||||
|
public interface IAppErrorHandler{
|
||||||
|
bool Log(string text);
|
||||||
|
void HandleException(string caption, string message, bool canIgnore, Exception e);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user