This commit is contained in:
34
Helpers/Logger.cs
Normal file
34
Helpers/Logger.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace ASTM_D7896_Tester.Services
|
||||
{
|
||||
public static class Logger
|
||||
{
|
||||
private static readonly object _lock = new object();
|
||||
private static string _logFilePath = "D7896_Test_Log.txt";
|
||||
|
||||
public static void Log(string message, bool toConsole = true, bool toFile = true)
|
||||
{
|
||||
string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||||
string logLine = $"{timestamp} - {message}";
|
||||
|
||||
if (toConsole)
|
||||
Debug.WriteLine(logLine);
|
||||
|
||||
if (toFile)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
File.AppendAllText(_logFilePath, logLine + Environment.NewLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogData(string label, double value, string unit = "")
|
||||
{
|
||||
Log($"{label}: {value:F6} {unit}".Trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user