Created
June 8, 2018 16:05
-
-
Save strvmarv/45d31e575b0b9168ca1f410621e4d836 to your computer and use it in GitHub Desktop.
This file contains 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
public class Program | |
{ | |
static void Main(string[] args) | |
{ | |
StackifyLib.Utils.StackifyAPILogger.OnLogMessage += StackifyAPILogger_OnLogMessage; | |
StackifyLib.Utils.StackifyAPILogger.LogEnabled = true; | |
} | |
private static void StackifyAPILogger_OnLogMessage(string data) | |
{ | |
try | |
{ | |
const string logDir = "StackifyLibLogs"; // This can be whatever name you choose | |
const string logFileName = "Log.txt"; // This can be whatever name you choose | |
// Get system drive, in case it's not C: | |
var systemDrive = System.IO.Path.GetPathRoot(System.Environment.SystemDirectory); | |
// e.g. C:\StackifyLibLogs | |
var path = System.IO.Path.Combine(systemDrive, logDir); | |
// e.g. C:\StackifyLibLogs\Log.txt | |
var fullPath = System.IO.Path.Combine(path, logFileName); | |
// Redundant directory exists check | |
if (System.IO.Directory.Exists(path) == false) | |
{ | |
System.IO.Directory.CreateDirectory(path); | |
} | |
// Append to single file, always flush | |
using (var sw = new System.IO.StreamWriter(fullPath, true)) | |
{ | |
sw.WriteLine(data); | |
sw.Flush(); | |
} | |
} | |
catch { /* ignored */ } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment