Last active
September 1, 2018 04:55
-
-
Save matthewoestreich/43842510d093549a2523be7635f50b63 to your computer and use it in GitHub Desktop.
using 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; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.IO; | |
using DnsUpdater.ExtensionsMethods; | |
namespace DnsUpdater | |
{ | |
public enum LogSeverity | |
{ | |
INFO, | |
ERROR, | |
SUCCESS, | |
FAILURE, | |
IP_CHANGED | |
} | |
class LogFile | |
{ | |
public delegate void Log(string value); | |
public string LogFilePath { get { return _logFilePath; } } | |
private string _logFilePath { get; set; } | |
public LogFile(string logFilePath) | |
{ | |
_logFilePath = logFilePath; | |
} | |
public void LogWriter(Log logFunction, string value) | |
{ | |
logFunction(value); | |
} | |
public void WriteInfo(string entry) | |
{ | |
File.AppendAllText( | |
_logFilePath, | |
entry.AddLogFileTimestamp(LogSeverity.INFO) | |
); | |
} | |
} | |
} | |
namespace DnsUpdater.ExtensionsMethods | |
{ | |
public static class ToTimestamps | |
{ | |
public static string AddLogFileTimestamp(this String str, LogSeverity severity) | |
{ | |
return string.Format( | |
"[[{0}][{1}]] {2}", | |
severity, | |
DateTime.Now.ToString("MM/dd/yyyy@hh:mm:sstt"), | |
str | |
) + Environment.NewLine; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment