Last active
August 2, 2023 00:58
-
-
Save thatcosmonaut/cdf4a2efb88a9b4186e9c335a0a0ef3a to your computer and use it in GitHub Desktop.
Samurai Gunn 2 Logger System
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 characters
using System.IO; | |
namespace SamuraiGunn2 | |
{ | |
public static class Logger | |
{ | |
private static StreamWriter streamWriter; | |
public static void SetLogOutputFile(string filePath) | |
{ | |
if (streamWriter != null) | |
{ | |
streamWriter.Close(); | |
} | |
streamWriter = new StreamWriter(filePath); | |
} | |
public static void WriteLine(string message) | |
{ | |
if (streamWriter != null) | |
{ | |
streamWriter.WriteLine(message); | |
streamWriter.Flush(); | |
} | |
System.Console.WriteLine(message); | |
} | |
public static void Finish() | |
{ | |
if (streamWriter != null) | |
{ | |
streamWriter.Close(); | |
streamWriter = null; | |
} | |
} | |
} | |
} |
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 characters
/* SOMEWHERE NEAR THE TOP OF MAIN... */ | |
if (!System.IO.Directory.Exists(Title.UserDataDirectory)) | |
{ | |
System.IO.Directory.CreateDirectory(Title.UserDataDirectory); | |
} | |
Logger.SetLogOutputFile(System.IO.Path.Combine(Title.UserDataDirectory, "log.txt")); | |
// configure logging | |
MoonWorks.Logger.LogInfo = Logger.WriteLine; | |
MoonWorks.Logger.LogWarn = Logger.WriteLine; | |
MoonWorks.Logger.LogError = Logger.WriteLine; |
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 characters
using System.IO; | |
namespace SamuraiGunn2 | |
{ | |
public static class Title | |
{ | |
public static string UserDataDirectory = $"{Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData), "SamuraiGunn2MoonWorks")}"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment