Skip to content

Instantly share code, notes, and snippets.

@oze4
Last active September 1, 2018 04:55
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 oze4/43842510d093549a2523be7635f50b63 to your computer and use it in GitHub Desktop.
Save oze4/43842510d093549a2523be7635f50b63 to your computer and use it in GitHub Desktop.
using System;
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