Last active
October 24, 2024 15:23
-
-
Save mikey-t/7999228 to your computer and use it in GitHub Desktop.
Revisions
-
mikey-t revised this gist
Dec 17, 2013 . 1 changed file with 54 additions and 54 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,78 +1,78 @@ public class Output { private readonly string LogDirPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs"); private static Output _outputSingleton; private static Output OutputSingleton { get { if (_outputSingleton == null) { _outputSingleton = new Output(); } return _outputSingleton; } } public StreamWriter SW { get; set; } public Output() { EnsureLogDirectoryExists(); InstantiateStreamWriter(); } ~Output() { if (SW != null) { try { SW.Dispose(); } catch(ObjectDisposedException){} // object already disposed - ignore exception } } public static void WriteLine(string str) { Console.WriteLine(str); OutputSingleton.SW.WriteLine(str); } public static void Write(string str) { Console.Write(str); OutputSingleton.SW.Write(str); } private void InstantiateStreamWriter() { string filePath = Path.Combine(LogDirPath, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")) + ".txt"; try { SW = new StreamWriter(filePath); SW.AutoFlush = true; } catch (UnauthorizedAccessException ex) { throw new ApplicationException(string.Format("Access denied. Could not instantiate StreamWriter using path: {0}.", filePath), ex); } } private void EnsureLogDirectoryExists() { if (!Directory.Exists(LogDirPath)) { try { Directory.CreateDirectory(LogDirPath); } catch (UnauthorizedAccessException ex) { throw new ApplicationException(string.Format("Access denied. Could not create log directory using path: {0}.", LogDirPath), ex); } } } } -
mikey-t renamed this gist
Dec 17, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
mikey-t created this gist
Dec 17, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,78 @@ public class Output { private readonly string LogDirPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs"); private static Output _outputSingleton; private static Output OutputSingleton { get { if (_outputSingleton == null) { _outputSingleton = new Output(); } return _outputSingleton; } } public StreamWriter SW { get; set; } public Output() { EnsureLogDirectoryExists(); InstantiateStreamWriter(); } ~Output() { if (SW != null) { try { SW.Dispose(); } catch(ObjectDisposedException){} // object already disposed - ignore exception } } public static void WriteLine(string str) { Console.WriteLine(str); OutputSingleton.SW.WriteLine(str); } public static void Write(string str) { Console.Write(str); OutputSingleton.SW.Write(str); } private void InstantiateStreamWriter() { string filePath = Path.Combine(LogDirPath, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")) + ".txt"; try { SW = new StreamWriter(filePath); SW.AutoFlush = true; } catch (UnauthorizedAccessException ex) { throw new ApplicationException(string.Format("Access denied. Could not instantiate StreamWriter using path: {0}.", filePath), ex); } } private void EnsureLogDirectoryExists() { if (!Directory.Exists(LogDirPath)) { try { Directory.CreateDirectory(LogDirPath); } catch (UnauthorizedAccessException ex) { throw new ApplicationException(string.Format("Access denied. Could not create log directory using path: {0}.", LogDirPath), ex); } } } }