diff --git a/Changelog.md b/Changelog.md
index dd0d95c..0218ce9 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -1,5 +1,14 @@
# Changelog
+## 1.6.2 - 2022-01-30 - ProgrammLogger improved
+### New Features
+* ProgrammLogger can now have a path while init, so not need to move the file
+* Make it possible that two instances can use the same logfile
+* IniReader GetValue can now have a default that returns if no setting is found
+### Bugfixes
+### Changes
+* Codingstyles
+
## 1.6.1 - 2022-01-20 - ProgrammLogger Fixed
### New Features
### Bugfixes
diff --git a/Utils/InIReader.cs b/Utils/InIReader.cs
index 87951e7..d530b50 100644
--- a/Utils/InIReader.cs
+++ b/Utils/InIReader.cs
@@ -31,8 +31,7 @@ namespace BlubbFish.Utils {
return false;
}
- private InIReader(String filename)
- {
+ private InIReader(String filename) {
foreach (String path in search_path) {
if (File.Exists(path + Path.DirectorySeparatorChar + filename)) {
this.filename = path + Path.DirectorySeparatorChar + filename;
@@ -60,8 +59,7 @@ namespace BlubbFish.Utils {
///
/// Dateiname
///
- public static InIReader GetInstance(String filename)
- {
+ public static InIReader GetInstance(String filename) {
if (!instances.Keys.Contains(filename)) {
instances.Add(filename, new InIReader(filename));
}
@@ -70,8 +68,7 @@ namespace BlubbFish.Utils {
private void ReadAgain(Object sender, EventArgs e) => this.LoadFile();
- private void LoadFile()
- {
+ private void LoadFile() {
this.inifile = new Dictionary>();
StreamReader file = new StreamReader(this.filename);
List buf = new List();
@@ -152,12 +149,11 @@ namespace BlubbFish.Utils {
/// Name der Sektion
/// Name des Wertes
///
- public String GetValue(String section, String key)
- {
+ public String GetValue(String section, String key, String @default = null) {
if (!section.StartsWith("[")) {
section = "[" + section + "]";
}
- return this.inifile.Keys.Contains(section) && this.inifile[section].Keys.Contains(key) ? this.inifile[section][key] : null;
+ return this.inifile.Keys.Contains(section) && this.inifile[section].Keys.Contains(key) ? this.inifile[section][key] : @default;
}
///
diff --git a/Utils/ProgramLogger.cs b/Utils/ProgramLogger.cs
index 2866948..677af4a 100644
--- a/Utils/ProgramLogger.cs
+++ b/Utils/ProgramLogger.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using System.Runtime.InteropServices;
using System.Text;
namespace BlubbFish.Utils {
@@ -9,8 +10,8 @@ namespace BlubbFish.Utils {
private ConsoleWriter errout;
private String loggerfile;
- public ProgramLogger() {
- this.loggerfile = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "output.log";
+ public ProgramLogger(String path = null) {
+ this.loggerfile = path ?? Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "output.log";
this.Init(this.loggerfile);
this.AttachToFw();
this.SetOutputs();
@@ -26,7 +27,7 @@ namespace BlubbFish.Utils {
Console.Error.WriteLine("Cannot write to " + file);
throw new ArgumentException("Cannot write to " + file);
}
- this.fw = new FileWriter(file, false);
+ this.fw = new FileWriter(FileWriter.GetFileSteam(file, false));
this.stdout = new ConsoleWriter(Console.Out, ConsoleWriterEventArgs.ConsoleType.Info);
this.errout = new ConsoleWriter(Console.Error, ConsoleWriterEventArgs.ConsoleType.Error);
}
@@ -63,10 +64,15 @@ namespace BlubbFish.Utils {
File.Delete(this.loggerfile);
}
this.loggerfile = file;
- this.fw = new FileWriter(this.loggerfile, true);
+ this.fw = new FileWriter(FileWriter.GetFileSteam(this.loggerfile, true));
this.AttachToFw();
}
+ public void Dispose() {
+ this.DisattachToFw();
+ this.fw.Dispose();
+ }
+
private void FileCopy(String source, String target) {
using FileStream fread = new FileStream(source, FileMode.Open);
using FileStream fwrite = new FileStream(target, FileMode.Create);
@@ -95,9 +101,11 @@ namespace BlubbFish.Utils {
internal class FileWriter : StreamWriter {
private Boolean newline = true;
- public FileWriter(String path, Boolean append) : base(path, append) {
+ public FileWriter(FileStream fs) : base(fs) {
}
+ public static FileStream GetFileSteam(String path, Boolean append) => File.Open(path, append ? FileMode.Append : FileMode.Create, FileAccess.Write, RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? FileShare.Write : FileShare.ReadWrite);
+
public override Encoding Encoding => Encoding.UTF8;
public override Boolean AutoFlush { get => true; set => base.AutoFlush = value; }
diff --git a/Utils/Utils.csproj b/Utils/Utils.csproj
index 9da3f45..fb43f88 100644
--- a/Utils/Utils.csproj
+++ b/Utils/Utils.csproj
@@ -8,14 +8,15 @@
BlubbFish
BlubbFish
Utils.BlubbFish
- Copyright © BlubbFish 2014 - 20.01.2022
- 1.6.1
+ Copyright © BlubbFish 2014 - 30.01.2022
+ 1.6.2
de-DE
LICENSE
http://git.blubbfish.net/vs_utils/Utils
http://git.blubbfish.net/vs_utils/Utils.git
git
+ 1.6.2 - 2022-01-30 - ProgrammLogger improved
1.6.1 - 2022-01-20 - ProgrammLogger Fixed
1.6.0 - 2022-01-09 - HttpEndpoint added
1.5.0 - 2021-04-10 - Add GetEvent so you can call events by string; Add OwnSingeton class