Skip to content

Instantly share code, notes, and snippets.

@strvmarv
Created June 8, 2018 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save strvmarv/45d31e575b0b9168ca1f410621e4d836 to your computer and use it in GitHub Desktop.
Save strvmarv/45d31e575b0b9168ca1f410621e4d836 to your computer and use it in GitHub Desktop.
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