Add loglevel to logger and change DateTime to UtcNow

This commit is contained in:
Chax
2023-05-17 16:23:03 +02:00
parent 1c85b91f32
commit a71ebaedc3

View File

@@ -6,22 +6,24 @@ namespace AndroidSideloader
internal class Logger
{
public string logfile = Properties.Settings.Default.CurrentLogPath;
public static bool Log(string text, bool ret = true)
public static bool Log(string text, string logLevel = "NOTICE", bool ret = true)
{
string time = DateTime.Now.ToString("hh:mmtt(UTC): ");
if (text.Length > 5)
{
string newline = "\n";
if (text.Length > 40 && text.Contains("\n"))
{
newline += "\n\n";
}
try { File.AppendAllText(Properties.Settings.Default.CurrentLogPath, time + text + newline); } catch { }
if (text.Length <= 5)
return ret;
string time = DateTime.UtcNow.ToString("hh:mmtt(UTC): ");
string newline = text.Length > 40 && text.Contains("\n") ? "\n\n" : "\n";
string logEntry = time + "[" + logLevel.ToUpper() + "] " + text + newline;
try
{
File.AppendAllText(Properties.Settings.Default.CurrentLogPath, logEntry);
}
catch
{
// Handle the exception if necessary
}
return ret;
}
}