Last active
October 24, 2018 16:01
-
-
Save SamKr/b5f445d81ccb3a1d879fcdffc479dabd to your computer and use it in GitHub Desktop.
Log text to file
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
if (!Directory.Exists(Variables.LogDirectory)) Directory.CreateDirectory(Variables.LogDirectory); | |
var logFile = $"[{DateTime.Now:yyyy-MM-dd}] Log.txt"; | |
if (error) logFile = $"[{DateTime.Now:yyyy-MM-dd}] ErrorLog.txt"; | |
logFile = Path.Combine(Variables.LogDirectory, logFile); | |
using (var stream = new FileStream(logFile, FileMode.Append, FileAccess.Write)) | |
using (var writer = new StreamWriter(stream)) | |
{ | |
writer.WriteLine($"[{DateTime.Now:O}] {msg}"); | |
writer.Close(); | |
stream.Close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment