First Version Ever that runs a little bit

This commit is contained in:
BlubbFish 2016-01-26 14:20:42 +00:00
parent 1823bb05a1
commit 845b733326
2 changed files with 32 additions and 38 deletions

View File

@ -4,44 +4,38 @@ using System.Linq;
using System.Text; using System.Text;
using System.IO; using System.IO;
namespace BlubbFish.Utils namespace BlubbFish.Utils {
{ public class FileLogger {
public class FileLogger private static Dictionary<string, FileLogger> instances = new Dictionary<string, FileLogger>();
{ private StreamWriter file;
private static Dictionary<string, FileLogger> instances = new Dictionary<string, FileLogger>(); private FileLogger(string filename, bool append) {
private StreamWriter file; if(!File.Exists(filename)) {
private FileLogger(string filename, bool append) string folder = Path.GetDirectoryName(Path.GetFullPath(filename));
{ if(!Directory.Exists(folder)) {
if (!File.Exists(filename)) Directory.CreateDirectory(folder);
{
string folder = Path.GetDirectoryName(Path.GetFullPath(filename));
if (!Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
}
}
this.file = new StreamWriter(filename, append, Encoding.UTF8);
this.file.AutoFlush = true;
}
public static FileLogger getInstance(string filename, bool append)
{
if (!instances.Keys.Contains(filename))
{
instances.Add(filename, new FileLogger(filename, append));
}
return instances[filename];
}
public void setArray(string[] text)
{
this.file.Write(String.Join(file.NewLine, text) + file.NewLine);
this.file.Flush();
}
public void setLine(string text)
{
this.file.WriteLine(text);
this.file.Flush();
} }
}
this.file = new StreamWriter(filename, append, Encoding.UTF8);
this.file.AutoFlush = true;
} }
public static FileLogger getInstance(string filename, bool append) {
if(!instances.Keys.Contains(filename)) {
instances.Add(filename, new FileLogger(filename, append));
}
return instances[filename];
}
public void setArray(string[] text) {
this.file.Write(String.Join(file.NewLine, text) + file.NewLine);
this.file.Flush();
}
public void setLine(string text) {
this.file.WriteLine(text);
this.file.Flush();
}
public void setLine(string text, DateTime d) {
this.setLine(d.ToString("[yyyy-MM-dd HH:mm:ss.ffff] " + text));
}
}
} }

Binary file not shown.