[1.6.2] ProgrammLogger improved
This commit is contained in:
parent
e3d37988c9
commit
cc579102cb
@ -1,5 +1,14 @@
|
|||||||
# Changelog
|
# 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
|
## 1.6.1 - 2022-01-20 - ProgrammLogger Fixed
|
||||||
### New Features
|
### New Features
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
@ -31,8 +31,7 @@ namespace BlubbFish.Utils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private InIReader(String filename)
|
private InIReader(String filename) {
|
||||||
{
|
|
||||||
foreach (String path in search_path) {
|
foreach (String path in search_path) {
|
||||||
if (File.Exists(path + Path.DirectorySeparatorChar + filename)) {
|
if (File.Exists(path + Path.DirectorySeparatorChar + filename)) {
|
||||||
this.filename = path + Path.DirectorySeparatorChar + filename;
|
this.filename = path + Path.DirectorySeparatorChar + filename;
|
||||||
@ -60,8 +59,7 @@ namespace BlubbFish.Utils {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">Dateiname</param>
|
/// <param name="filename">Dateiname</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static InIReader GetInstance(String filename)
|
public static InIReader GetInstance(String filename) {
|
||||||
{
|
|
||||||
if (!instances.Keys.Contains(filename)) {
|
if (!instances.Keys.Contains(filename)) {
|
||||||
instances.Add(filename, new InIReader(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 ReadAgain(Object sender, EventArgs e) => this.LoadFile();
|
||||||
|
|
||||||
private void LoadFile()
|
private void LoadFile() {
|
||||||
{
|
|
||||||
this.inifile = new Dictionary<String, Dictionary<String, String>>();
|
this.inifile = new Dictionary<String, Dictionary<String, String>>();
|
||||||
StreamReader file = new StreamReader(this.filename);
|
StreamReader file = new StreamReader(this.filename);
|
||||||
List<String> buf = new List<String>();
|
List<String> buf = new List<String>();
|
||||||
@ -152,12 +149,11 @@ namespace BlubbFish.Utils {
|
|||||||
/// <param name="section">Name der Sektion</param>
|
/// <param name="section">Name der Sektion</param>
|
||||||
/// <param name="key">Name des Wertes</param>
|
/// <param name="key">Name des Wertes</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public String GetValue(String section, String key)
|
public String GetValue(String section, String key, String @default = null) {
|
||||||
{
|
|
||||||
if (!section.StartsWith("[")) {
|
if (!section.StartsWith("[")) {
|
||||||
section = "[" + section + "]";
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace BlubbFish.Utils {
|
namespace BlubbFish.Utils {
|
||||||
@ -9,8 +10,8 @@ namespace BlubbFish.Utils {
|
|||||||
private ConsoleWriter errout;
|
private ConsoleWriter errout;
|
||||||
private String loggerfile;
|
private String loggerfile;
|
||||||
|
|
||||||
public ProgramLogger() {
|
public ProgramLogger(String path = null) {
|
||||||
this.loggerfile = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "output.log";
|
this.loggerfile = path ?? Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "output.log";
|
||||||
this.Init(this.loggerfile);
|
this.Init(this.loggerfile);
|
||||||
this.AttachToFw();
|
this.AttachToFw();
|
||||||
this.SetOutputs();
|
this.SetOutputs();
|
||||||
@ -26,7 +27,7 @@ namespace BlubbFish.Utils {
|
|||||||
Console.Error.WriteLine("Cannot write to " + file);
|
Console.Error.WriteLine("Cannot write to " + file);
|
||||||
throw new ArgumentException("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.stdout = new ConsoleWriter(Console.Out, ConsoleWriterEventArgs.ConsoleType.Info);
|
||||||
this.errout = new ConsoleWriter(Console.Error, ConsoleWriterEventArgs.ConsoleType.Error);
|
this.errout = new ConsoleWriter(Console.Error, ConsoleWriterEventArgs.ConsoleType.Error);
|
||||||
}
|
}
|
||||||
@ -63,10 +64,15 @@ namespace BlubbFish.Utils {
|
|||||||
File.Delete(this.loggerfile);
|
File.Delete(this.loggerfile);
|
||||||
}
|
}
|
||||||
this.loggerfile = file;
|
this.loggerfile = file;
|
||||||
this.fw = new FileWriter(this.loggerfile, true);
|
this.fw = new FileWriter(FileWriter.GetFileSteam(this.loggerfile, true));
|
||||||
this.AttachToFw();
|
this.AttachToFw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose() {
|
||||||
|
this.DisattachToFw();
|
||||||
|
this.fw.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
private void FileCopy(String source, String target) {
|
private void FileCopy(String source, String target) {
|
||||||
using FileStream fread = new FileStream(source, FileMode.Open);
|
using FileStream fread = new FileStream(source, FileMode.Open);
|
||||||
using FileStream fwrite = new FileStream(target, FileMode.Create);
|
using FileStream fwrite = new FileStream(target, FileMode.Create);
|
||||||
@ -95,9 +101,11 @@ namespace BlubbFish.Utils {
|
|||||||
|
|
||||||
internal class FileWriter : StreamWriter {
|
internal class FileWriter : StreamWriter {
|
||||||
private Boolean newline = true;
|
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 Encoding Encoding => Encoding.UTF8;
|
||||||
public override Boolean AutoFlush { get => true; set => base.AutoFlush = value; }
|
public override Boolean AutoFlush { get => true; set => base.AutoFlush = value; }
|
||||||
|
|
||||||
|
@ -8,14 +8,15 @@
|
|||||||
<Company>BlubbFish</Company>
|
<Company>BlubbFish</Company>
|
||||||
<Authors>BlubbFish</Authors>
|
<Authors>BlubbFish</Authors>
|
||||||
<PackageId>Utils.BlubbFish</PackageId>
|
<PackageId>Utils.BlubbFish</PackageId>
|
||||||
<Copyright>Copyright © BlubbFish 2014 - 20.01.2022</Copyright>
|
<Copyright>Copyright © BlubbFish 2014 - 30.01.2022</Copyright>
|
||||||
<Version>1.6.1</Version>
|
<Version>1.6.2</Version>
|
||||||
<NeutralLanguage>de-DE</NeutralLanguage>
|
<NeutralLanguage>de-DE</NeutralLanguage>
|
||||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||||
<PackageProjectUrl>http://git.blubbfish.net/vs_utils/Utils</PackageProjectUrl>
|
<PackageProjectUrl>http://git.blubbfish.net/vs_utils/Utils</PackageProjectUrl>
|
||||||
<RepositoryUrl>http://git.blubbfish.net/vs_utils/Utils.git</RepositoryUrl>
|
<RepositoryUrl>http://git.blubbfish.net/vs_utils/Utils.git</RepositoryUrl>
|
||||||
<RepositoryType>git</RepositoryType>
|
<RepositoryType>git</RepositoryType>
|
||||||
<PackageReleaseNotes>
|
<PackageReleaseNotes>
|
||||||
|
1.6.2 - 2022-01-30 - ProgrammLogger improved
|
||||||
1.6.1 - 2022-01-20 - ProgrammLogger Fixed
|
1.6.1 - 2022-01-20 - ProgrammLogger Fixed
|
||||||
1.6.0 - 2022-01-09 - HttpEndpoint added
|
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
|
1.5.0 - 2021-04-10 - Add GetEvent so you can call events by string; Add OwnSingeton class
|
||||||
|
Loading…
Reference in New Issue
Block a user