[1.2.6] Makeing Logging easyier

This commit is contained in:
BlubbFish 2022-01-25 23:28:11 +01:00
parent 1862aa7da2
commit 8e41d15e4e
7 changed files with 43 additions and 10 deletions

View File

@ -1,12 +1,27 @@
using System; using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.Loader; using System.Runtime.Loader;
using System.Threading; using System.Threading;
namespace BlubbFish.Utils.IoT.Bots { namespace BlubbFish.Utils.IoT.Bots {
public abstract class ABot { public abstract class ABot {
private Boolean RunningProcess = true; 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<String>() { "/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) { private void ConsoleCancelEvent(Object sender, ConsoleCancelEventArgs e) {
e.Cancel = true; e.Cancel = true;
@ -37,6 +52,7 @@ namespace BlubbFish.Utils.IoT.Bots {
public virtual void Dispose() { public virtual void Dispose() {
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.Dispose: Shutdown."); Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.Dispose: Shutdown.");
this.RunningProcess = false; this.RunningProcess = false;
this.logger?.Dispose();
} }
} }
} }

View File

@ -12,7 +12,7 @@ namespace BlubbFish.Utils.IoT.Bots {
protected HttpListener httplistener; protected HttpListener httplistener;
public AWebserver(Dictionary<String, String> settings) => this.config = settings; public AWebserver(String[] args, Boolean fileLogging, String configSearchPath, Dictionary<String, String> settings) : base(args, fileLogging, configSearchPath) => this.config = settings;
protected void StartListen() { protected void StartListen() {
this.httplistener = new HttpListener(); this.httplistener = new HttpListener();

View File

@ -7,7 +7,7 @@ using BlubbFish.Utils.IoT.Events;
namespace BlubbFish.Utils.IoT.Bots { namespace BlubbFish.Utils.IoT.Bots {
public abstract class AWebserverDataBackend : AWebserver { public abstract class AWebserverDataBackend : AWebserver {
protected ABackend databackend; protected ABackend databackend;
protected AWebserverDataBackend(ABackend backend, Dictionary<String, String> settings) : base(settings) => this.databackend = backend; protected AWebserverDataBackend(String[] args, Boolean fileLogging, String configSearchPath, ABackend backend, Dictionary<String, String> settings) : base(args, fileLogging, configSearchPath, settings) => this.databackend = backend;
protected void StartDataBackend() => this.databackend.MessageIncomming += this.Backend_MessageIncomming; protected void StartDataBackend() => this.databackend.MessageIncomming += this.Backend_MessageIncomming;

View File

@ -5,17 +5,18 @@
<RootNamespace>BlubbFish.Utils.IoT.Bots</RootNamespace> <RootNamespace>BlubbFish.Utils.IoT.Bots</RootNamespace>
<AssemblyName>Bot-Utils</AssemblyName> <AssemblyName>Bot-Utils</AssemblyName>
<PackageId>Bots.IoT.Utils.BlubbFish</PackageId> <PackageId>Bots.IoT.Utils.BlubbFish</PackageId>
<Version>1.2.5</Version> <Version>1.2.6</Version>
<NeutralLanguage>de-DE</NeutralLanguage> <NeutralLanguage>de-DE</NeutralLanguage>
<Description>Bot-Utils are helpers for programming a bot</Description> <Description>Bot-Utils are helpers for programming a bot</Description>
<Authors>BlubbFish</Authors> <Authors>BlubbFish</Authors>
<Company>BlubbFish</Company> <Company>BlubbFish</Company>
<Copyright>Copyright © BlubbFish 2018 - 20.01.2022</Copyright> <Copyright>Copyright © BlubbFish 2018 - 25.01.2022</Copyright>
<PackageLicenseFile>LICENSE</PackageLicenseFile> <PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageProjectUrl>http://git.blubbfish.net/vs_utils/Bot-Utils</PackageProjectUrl> <PackageProjectUrl>http://git.blubbfish.net/vs_utils/Bot-Utils</PackageProjectUrl>
<RepositoryUrl>http://git.blubbfish.net/vs_utils/Bot-Utils.git</RepositoryUrl> <RepositoryUrl>http://git.blubbfish.net/vs_utils/Bot-Utils.git</RepositoryUrl>
<RepositoryType>git</RepositoryType> <RepositoryType>git</RepositoryType>
<PackageReleaseNotes> <PackageReleaseNotes>
1.2.6 - 2022-01-25 - Makeing Logging easyier
1.2.5 - 2022-01-20 - Better linux handling 1.2.5 - 2022-01-20 - Better linux handling
1.2.4 - 2022-01-18 - Config enabled module loading 1.2.4 - 2022-01-18 - Config enabled module loading
1.2.3 - 2022-01-09 - Tiny Refactoring 1.2.3 - 2022-01-09 - Tiny Refactoring

View File

@ -9,6 +9,8 @@ namespace BlubbFish.Utils.IoT.Bots {
public abstract class Bot<T> : ABot { public abstract class Bot<T> : ABot {
protected readonly Dictionary<String, AModul<T>> moduls = new Dictionary<String, AModul<T>>(); protected readonly Dictionary<String, AModul<T>> moduls = new Dictionary<String, AModul<T>>();
public Bot(String[] args, Boolean fileLogging, String configSearchPath) : base(args, fileLogging, configSearchPath) { }
protected void ModulDispose() { protected void ModulDispose() {
foreach (KeyValuePair<String, AModul<T>> item in this.moduls) { foreach (KeyValuePair<String, AModul<T>> item in this.moduls) {
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.ModulDispose: Entlade Modul: " + item.Key); 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());
}
}
} }
} }

View File

@ -1,8 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BlubbFish.Utils.IoT.Connector; using BlubbFish.Utils.IoT.Connector;
namespace BlubbFish.Utils.IoT.Bots { namespace BlubbFish.Utils.IoT.Bots {
@ -10,7 +8,7 @@ namespace BlubbFish.Utils.IoT.Bots {
protected Dictionary<String, ABackend> sources; protected Dictionary<String, ABackend> sources;
protected Dictionary<String, String> settings; protected Dictionary<String, String> settings;
protected MultiSourceBot(Dictionary<String, ABackend> sources, Dictionary<String, String> settings) { protected MultiSourceBot(String[] args, Boolean fileLogging, String configSearchPath, Dictionary<String, ABackend> sources, Dictionary<String, String> settings) : base(args, fileLogging, configSearchPath) {
this.sources = sources; this.sources = sources;
this.settings = settings; this.settings = settings;
} }

View File

@ -1,5 +1,17 @@
# Changelog # 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 ## 1.2.5 - 2022-01-20 - Better linux handling
### New Features ### New Features
* Add ProcessExit Handler in ABot * Add ProcessExit Handler in ABot