mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-09 06:15:49 +02:00
Add IAppErrorHandler w/ implementation
This commit is contained in:
parent
da706d7ed8
commit
77030c9b23
@ -58,6 +58,7 @@ static Program(){
|
||||
Config = new ConfigManager();
|
||||
|
||||
Lib.Initialize(new App.Builder{
|
||||
ErrorHandler = Reporter
|
||||
});
|
||||
}
|
||||
|
||||
|
11
Reporter.cs
11
Reporter.cs
@ -7,9 +7,10 @@
|
||||
using TweetDuck.Configuration;
|
||||
using TweetDuck.Core.Other;
|
||||
using TweetLib.Core;
|
||||
using TweetLib.Core.Application;
|
||||
|
||||
namespace TweetDuck{
|
||||
sealed class Reporter{
|
||||
sealed class Reporter : IAppErrorHandler{
|
||||
private readonly string logFile;
|
||||
|
||||
public Reporter(string logFile){
|
||||
@ -29,8 +30,12 @@ public bool LogVerbose(string data){
|
||||
}
|
||||
|
||||
public bool LogImportant(string data){
|
||||
return ((IAppErrorHandler)this).Log(data);
|
||||
}
|
||||
|
||||
bool IAppErrorHandler.Log(string text){
|
||||
#if DEBUG
|
||||
Debug.WriteLine(data);
|
||||
Debug.WriteLine(text);
|
||||
#endif
|
||||
|
||||
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(data).Append("\r\n\r\n");
|
||||
build.Append(text).Append("\r\n\r\n");
|
||||
|
||||
try{
|
||||
File.AppendAllText(logFile, build.ToString(), Encoding.UTF8);
|
||||
|
@ -3,14 +3,17 @@
|
||||
|
||||
namespace TweetLib.Core{
|
||||
public sealed class App{
|
||||
public static IAppErrorHandler ErrorHandler { get; private set; }
|
||||
|
||||
// Builder
|
||||
|
||||
public sealed class Builder{
|
||||
public IAppErrorHandler? ErrorHandler { get; set; }
|
||||
|
||||
// Validation
|
||||
|
||||
internal void Initialize(){
|
||||
App.ErrorHandler = Validate(ErrorHandler, nameof(ErrorHandler))!;
|
||||
}
|
||||
|
||||
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