Skip to content

Commit

Permalink
log pruning
Browse files Browse the repository at this point in the history
  • Loading branch information
wiegell committed Nov 29, 2022
1 parent 5ec0cd7 commit 04b3845
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion AstroWall/BusinessLayer/Logging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace AstroWall.BusinessLayer
public class Logging
{

// Formatting
private static string dateFormat = "dd/MM-yy--HH:mm:ss";

//Singleton
private static volatile Logging instance;
private static object syncRoot = new object();
Expand All @@ -31,6 +34,7 @@ public static Logging Instance

public Logging()
{
pruneLogFile();
sw = File.AppendText(General.getLogPath());
}

Expand All @@ -40,13 +44,20 @@ public static Action<string> GetLogger(string caller, bool isError = false)
{
lock (syncRoot)
{
string logStr = (isError ? "ERROR: " : "") + DateTime.Now.ToString("dd/MM-yy--HH:mm:ss") + ", " + caller + ": " + log;
string logStr = (isError ? "ERROR: " : "") + DateTime.Now.ToString(dateFormat) + ", " + caller + ": " + log;
Logging.Instance.sw.WriteLine(logStr);
Logging.Instance.sw.Flush();
Console.WriteLine(logStr);
}
};
}

private void pruneLogFile()
{
string path = General.getLogPath();
long size = (new FileInfo(path)).Length;
if (size > 5000000) File.Delete(path);
}
}
}

0 comments on commit 04b3845

Please sign in to comment.