From acf90704a8ee221490c91c4e53d1d1a798b89aed Mon Sep 17 00:00:00 2001 From: BlubbFish Date: Wed, 8 Jun 2016 11:25:47 +0000 Subject: [PATCH] [NF] now it's easier to specifiy a directory for logging --- FileLogger.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/FileLogger.cs b/FileLogger.cs index a49364c..c08bf47 100644 --- a/FileLogger.cs +++ b/FileLogger.cs @@ -3,12 +3,15 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; +using System.Reflection; namespace BlubbFish.Utils { public class FileLogger { private static Dictionary instances = new Dictionary(); + private static String logDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar; private StreamWriter file; private FileLogger(string filename, bool append) { + filename = logDir + filename; if(!File.Exists(filename)) { string folder = Path.GetDirectoryName(Path.GetFullPath(filename)); if(!Directory.Exists(folder)) { @@ -25,6 +28,20 @@ namespace BlubbFish.Utils { return instances[filename]; } + public static void setLogDir(String v) { + v = v.Replace("..", ""); + v = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar + v; + if(Directory.Exists(v)) { + logDir = v; + } else { + Directory.CreateDirectory(v); + logDir = v; + } + if(logDir.Substring(logDir.Length - 1) != Path.DirectorySeparatorChar.ToString()) { + logDir = logDir + Path.DirectorySeparatorChar; + } + } + public void setArray(string[] text) { this.file.Write(String.Join(file.NewLine, text) + file.NewLine); this.file.Flush();