use ToDisplayString
This commit is contained in:
parent
b0e44d5cce
commit
146daed8d9
|
@ -5,20 +5,20 @@ namespace InnovEnergy.App.SaliMax;
|
|||
|
||||
public class CustomLogger : ILogger
|
||||
{
|
||||
private readonly String _logFilePath;
|
||||
private readonly Int64 _maxFileSizeBytes;
|
||||
private readonly Int32 _maxLogFileCount;
|
||||
private Int64 _currentFileSizeBytes;
|
||||
private readonly String _LogFilePath;
|
||||
private readonly Int64 _MaxFileSizeBytes;
|
||||
private readonly Int32 _MaxLogFileCount;
|
||||
private Int64 _CurrentFileSizeBytes;
|
||||
|
||||
public CustomLogger(String logFilePath, Int64 maxFileSizeBytes, Int32 maxLogFileCount)
|
||||
{
|
||||
_logFilePath = logFilePath;
|
||||
_maxFileSizeBytes = maxFileSizeBytes;
|
||||
_maxLogFileCount = maxLogFileCount;
|
||||
_currentFileSizeBytes = File.Exists(logFilePath) ? new FileInfo(logFilePath).Length : 0;
|
||||
_LogFilePath = logFilePath;
|
||||
_MaxFileSizeBytes = maxFileSizeBytes;
|
||||
_MaxLogFileCount = maxLogFileCount;
|
||||
_CurrentFileSizeBytes = File.Exists(logFilePath) ? new FileInfo(logFilePath).Length : 0;
|
||||
}
|
||||
|
||||
public IDisposable BeginScope<TState>(TState state)
|
||||
public IDisposable? BeginScope<TState>(TState state) where TState : notnull
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -33,35 +33,34 @@ public class CustomLogger : ILogger
|
|||
var logMessage = formatter(state, exception!);
|
||||
|
||||
// Check the file size and rotate the log file if necessary
|
||||
if (_currentFileSizeBytes + logMessage.Length >= _maxFileSizeBytes)
|
||||
if (_CurrentFileSizeBytes + logMessage.Length >= _MaxFileSizeBytes)
|
||||
{
|
||||
RotateLogFile();
|
||||
_currentFileSizeBytes = 0;
|
||||
_CurrentFileSizeBytes = 0;
|
||||
}
|
||||
|
||||
// Write the log message to the file
|
||||
File.AppendAllText(_logFilePath, logMessage + Environment.NewLine);
|
||||
_currentFileSizeBytes += logMessage.Length;
|
||||
File.AppendAllText(_LogFilePath, logMessage + Environment.NewLine);
|
||||
_CurrentFileSizeBytes += logMessage.Length;
|
||||
}
|
||||
|
||||
private void RotateLogFile()
|
||||
{
|
||||
// Check the log file count and delete the oldest file if necessary
|
||||
var logFileDir = Path.GetDirectoryName(_logFilePath)!;
|
||||
var logFileExt = Path.GetExtension(_logFilePath);
|
||||
var logFileBaseName = Path.GetFileNameWithoutExtension(_logFilePath);
|
||||
var logFileDir = Path.GetDirectoryName(_LogFilePath)!;
|
||||
var logFileExt = Path.GetExtension(_LogFilePath);
|
||||
var logFileBaseName = Path.GetFileNameWithoutExtension(_LogFilePath);
|
||||
|
||||
var logFiles = Directory.GetFiles(logFileDir, $"{logFileBaseName}_*{logFileExt}")
|
||||
.OrderBy(file => file)
|
||||
.ToList();
|
||||
var logFiles = Directory
|
||||
.GetFiles(logFileDir, $"{logFileBaseName}_*{logFileExt}")
|
||||
.OrderBy(file => file)
|
||||
.ToList();
|
||||
|
||||
if (logFiles.Count >= _maxLogFileCount)
|
||||
{
|
||||
if (logFiles.Count >= _MaxLogFileCount)
|
||||
File.Delete(logFiles.First());
|
||||
}
|
||||
|
||||
// Rename the current log file with a timestamp
|
||||
var logFileBackupPath = Path.Combine(logFileDir, $"{logFileBaseName}_{UnixTime.Now}{logFileExt}");
|
||||
File.Move(_logFilePath, logFileBackupPath);
|
||||
File.Move(_LogFilePath, logFileBackupPath);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -241,11 +241,11 @@ internal static class Program
|
|||
// Voltage Measurement Values
|
||||
//var inverterVoltage = new Voltage [(Int32)s.AcDc.Ac.L1.Voltage, (Int32)s.AcDc.Ac.L2.Voltage, (Int32)s.AcDc.Ac.L3.Voltage];
|
||||
//var dcLinkVoltage = s.DcDc.Dc.Link.Voltage;
|
||||
var dc48Voltage = s.DcDc.Dc.Battery.Voltage;
|
||||
var batteryVoltage = s.Battery.Dc.Voltage;
|
||||
var batterySoc = s.Battery.Soc;
|
||||
var batteryCurrent = s.Battery.Dc.Current;
|
||||
var batteryTemp = s.Battery.Temperature;
|
||||
var dc48Voltage = s.DcDc.Dc.Battery.Voltage.ToDisplayString();
|
||||
var batteryVoltage = s.Battery.Dc.Voltage.ToDisplayString();
|
||||
var batterySoc = s.Battery.Soc.ToDisplayString();
|
||||
var batteryCurrent = s.Battery.Dc.Current.ToDisplayString();
|
||||
var batteryTemp = s.Battery.Temperature.ToDisplayString();
|
||||
|
||||
var gridBusColumn = ColumnBox("Pv", "Grid Bus", "Load" , gridVoltageByPhase , gridLoadPower);
|
||||
var islandBusColumn = ColumnBox("Pv", "Island Bus", "Load" , inverterPowerByPhase, islandLoadPower);
|
||||
|
@ -260,10 +260,10 @@ internal static class Program
|
|||
var gridBox = TextBlock.AlignLeft(gridPowerByPhase).TitleBox("Grid");
|
||||
var inverterBox = TextBlock.AlignLeft(inverterPowerByAcDc).TitleBox("Inverter");
|
||||
var dcDcBox = TextBlock.AlignLeft(dc48Voltage).TitleBox("DC/DC");
|
||||
var batteryAvgBox = TextBlock.AlignLeft(batteryVoltage.ToDisplayString(),
|
||||
batterySoc.ToDisplayString(),
|
||||
batteryCurrent.ToDisplayString(),
|
||||
batteryTemp.ToDisplayString())
|
||||
var batteryAvgBox = TextBlock.AlignLeft(batteryVoltage,
|
||||
batterySoc,
|
||||
batteryCurrent,
|
||||
batteryTemp)
|
||||
.TitleBox("Battery");
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue