Created
February 22, 2019 18:09
-
-
Save FusRoDah061/e8115483d52e1768e90644b5ed404c02 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 Logger | |
{ | |
public static void Log(object msg, bool newLine = true) | |
{ | |
string message = "<" + DateTime.Now.ToString() + "> " + msg.ToString() + ((newLine) ? "\n" : ""); | |
Console.Write(message); | |
LogFile(message, _getFileName()); | |
} | |
public static void Log(Exception ex) | |
{ | |
string message = "<" + DateTime.Now.ToString() + "> " + ex.ToString(); | |
Console.Write(message); | |
LogFile(message, _getFileName()); | |
} | |
public static void LogFile(object msg, string filename, bool append = true) | |
{ | |
try | |
{ | |
if (append) | |
{ | |
File.AppendAllText(filename, "\r\n<" + DateTime.Now.ToString() + "> " + msg.ToString()); | |
} | |
else | |
{ | |
File.WriteAllText(filename, "\r\n<" + DateTime.Now.ToString() + "> " + msg.ToString()); | |
} | |
} catch { } | |
} | |
private static string _getFileName() | |
{ | |
return "log_" + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + ".log"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment