diff --git a/Bot-Utils/ABot.cs b/Bot-Utils/ABot.cs index 7965a80..f7bb3af 100644 --- a/Bot-Utils/ABot.cs +++ b/Bot-Utils/ABot.cs @@ -1,12 +1,27 @@ using System; +using System.Collections.Generic; +using System.Reflection; using System.Runtime.Loader; using System.Threading; namespace BlubbFish.Utils.IoT.Bots { public abstract class ABot { private Boolean RunningProcess = true; + private readonly ProgramLogger logger = null; - protected ProgramLogger logger = new ProgramLogger(); + public Boolean DebugLogging { + get; + } + + public ABot(String[] _, Boolean fileLogging, String configSearchPath) { + InIReader.SetSearchPath(new List() { "/etc/"+ configSearchPath, Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\"+ configSearchPath }); + if(fileLogging) { + this.logger = new ProgramLogger(InIReader.GetInstance("settings").GetValue("logging", "path", Assembly.GetEntryAssembly().GetName().Name + ".log")); + } + if(Boolean.TryParse(InIReader.GetInstance("settings").GetValue("logging", "debug", "true"), out Boolean debuglog)) { + this.DebugLogging = debuglog; + } + } private void ConsoleCancelEvent(Object sender, ConsoleCancelEventArgs e) { e.Cancel = true; @@ -37,6 +52,7 @@ namespace BlubbFish.Utils.IoT.Bots { public virtual void Dispose() { Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.Dispose: Shutdown."); this.RunningProcess = false; + this.logger?.Dispose(); } } } diff --git a/Bot-Utils/AWebserver.cs b/Bot-Utils/AWebserver.cs index e52305f..da44cc7 100644 --- a/Bot-Utils/AWebserver.cs +++ b/Bot-Utils/AWebserver.cs @@ -12,7 +12,7 @@ namespace BlubbFish.Utils.IoT.Bots { protected HttpListener httplistener; - public AWebserver(Dictionary settings) => this.config = settings; + public AWebserver(String[] args, Boolean fileLogging, String configSearchPath, Dictionary settings) : base(args, fileLogging, configSearchPath) => this.config = settings; protected void StartListen() { this.httplistener = new HttpListener(); diff --git a/Bot-Utils/AWebserverDataBackend.cs b/Bot-Utils/AWebserverDataBackend.cs index 24edbec..fb9cb80 100644 --- a/Bot-Utils/AWebserverDataBackend.cs +++ b/Bot-Utils/AWebserverDataBackend.cs @@ -7,7 +7,7 @@ using BlubbFish.Utils.IoT.Events; namespace BlubbFish.Utils.IoT.Bots { public abstract class AWebserverDataBackend : AWebserver { protected ABackend databackend; - protected AWebserverDataBackend(ABackend backend, Dictionary settings) : base(settings) => this.databackend = backend; + protected AWebserverDataBackend(String[] args, Boolean fileLogging, String configSearchPath, ABackend backend, Dictionary settings) : base(args, fileLogging, configSearchPath, settings) => this.databackend = backend; protected void StartDataBackend() => this.databackend.MessageIncomming += this.Backend_MessageIncomming; diff --git a/Bot-Utils/Bot-Utils.csproj b/Bot-Utils/Bot-Utils.csproj index 09cf5ba..01bee3a 100644 --- a/Bot-Utils/Bot-Utils.csproj +++ b/Bot-Utils/Bot-Utils.csproj @@ -5,17 +5,18 @@ BlubbFish.Utils.IoT.Bots Bot-Utils Bots.IoT.Utils.BlubbFish - 1.2.5 + 1.2.6 de-DE Bot-Utils are helpers for programming a bot BlubbFish BlubbFish - Copyright © BlubbFish 2018 - 20.01.2022 + Copyright © BlubbFish 2018 - 25.01.2022 LICENSE http://git.blubbfish.net/vs_utils/Bot-Utils http://git.blubbfish.net/vs_utils/Bot-Utils.git git + 1.2.6 - 2022-01-25 - Makeing Logging easyier 1.2.5 - 2022-01-20 - Better linux handling 1.2.4 - 2022-01-18 - Config enabled module loading 1.2.3 - 2022-01-09 - Tiny Refactoring diff --git a/Bot-Utils/Bot.cs b/Bot-Utils/Bot.cs index 06c0553..521ca20 100644 --- a/Bot-Utils/Bot.cs +++ b/Bot-Utils/Bot.cs @@ -9,6 +9,8 @@ namespace BlubbFish.Utils.IoT.Bots { public abstract class Bot : ABot { protected readonly Dictionary> moduls = new Dictionary>(); + public Bot(String[] args, Boolean fileLogging, String configSearchPath) : base(args, fileLogging, configSearchPath) { } + protected void ModulDispose() { foreach (KeyValuePair> item in this.moduls) { Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.ModulDispose: Entlade Modul: " + item.Key); @@ -61,6 +63,10 @@ namespace BlubbFish.Utils.IoT.Bots { } } - protected void ModulUpdate(Object sender, ModulEventArgs e) => Console.WriteLine(e.ToString()); + protected void ModulUpdate(Object sender, ModulEventArgs e) { + if(this.DebugLogging) { + Console.WriteLine(e.ToString()); + } + } } } diff --git a/Bot-Utils/MultiSourceBot.cs b/Bot-Utils/MultiSourceBot.cs index 9b2bd28..08b6cf7 100644 --- a/Bot-Utils/MultiSourceBot.cs +++ b/Bot-Utils/MultiSourceBot.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; + using BlubbFish.Utils.IoT.Connector; namespace BlubbFish.Utils.IoT.Bots { @@ -10,7 +8,7 @@ namespace BlubbFish.Utils.IoT.Bots { protected Dictionary sources; protected Dictionary settings; - protected MultiSourceBot(Dictionary sources, Dictionary settings) { + protected MultiSourceBot(String[] args, Boolean fileLogging, String configSearchPath, Dictionary sources, Dictionary settings) : base(args, fileLogging, configSearchPath) { this.sources = sources; this.settings = settings; } diff --git a/Changelog.md b/Changelog.md index 84e4201..ddaf848 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,17 @@ # Changelog +## 1.2.6 - 2022-01-25 - Makeing Logging easyier +### New Features +* Construct the Programm logger only if enabled +* Set Searchpath by default for a Bot +* Add an option that allows to debug logging (by default on) +### Bugfixes +### Changes +* Deconstruct Programmlogger +* Change all classes that extend ABot +* Module messages also uses debug logging flag +* Codingstyles + ## 1.2.5 - 2022-01-20 - Better linux handling ### New Features * Add ProcessExit Handler in ABot