Skip to content

Commit

Permalink
added more loggings and checks
Browse files Browse the repository at this point in the history
  • Loading branch information
SIRprise committed Oct 5, 2022
1 parent 3df4b52 commit a8a9696
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 9 deletions.
85 changes: 80 additions & 5 deletions SSD-LED/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Timers;
using System.Windows.Forms;
using Serilog;
using System.Configuration;

namespace SSD_LED
{
Expand Down Expand Up @@ -68,9 +69,19 @@ public SSDLED()
{
InitializeComponent();

//var test = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
//var logFilePath = Path.Combine(Environment.GetEnvironmentVariable("LocalAppData"), "log.txt");

//var appConfigPath = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;

var userConfigPath = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
var logFilePath = Path.Combine(Path.GetDirectoryName(userConfigPath.FilePath), "SSDLED.log");



Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.WriteTo.File("logs/ssd_led.log", rollingInterval: RollingInterval.Day, fileSizeLimitBytes: 1024*100)
.WriteTo.File(logFilePath, rollingInterval: RollingInterval.Day, fileSizeLimitBytes: 1024*100)
.CreateLogger();

Log.Information("Starting "+ NameAndVersion());
Expand Down Expand Up @@ -104,7 +115,8 @@ public SSDLED()

label1.Text = NameAndVersion() + " by SIRprise";

loadSettings();
if(loadSettings() == false)
Log.Error("Error while parsing settings");

maxSpeedKBS = trackBar1.Value;
textBox1.Text = maxSpeedKBS + " KB/s";
Expand Down Expand Up @@ -687,33 +699,91 @@ private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
comboBox1.Enabled = false;
diskSelectionPFCStr = null;
Log.Information("Changed single drive monitoring - checked status: " + checkBox1.Checked);
}
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
diskSelectionPFCStr = GetInstanceNameByDriveIndex(comboBox1.SelectedIndex);
Debug.WriteLine("Selected: " + diskSelectionPFCStr);
string backupSelectionStr = diskSelectionPFCStr;
try
{
diskSelectionPFCStr = GetInstanceNameByDriveIndex(comboBox1.SelectedIndex);
Debug.WriteLine("Selected: " + diskSelectionPFCStr);
Log.Information("Selected single drive: " + comboBox1.Text + " which is index " + comboBox1.SelectedIndex + " of the drive list");
}
catch
{
Log.Error("Changed drive selection didn't work!");
//unselect
comboBox1.SelectedIndex = -1;
diskSelectionPFCStr = backupSelectionStr;
checkBox1.Checked = false;
MessageBox.Show("Error while selection - aborting...");
}
}

#endregion

#region settings load and save
private bool loadSettings()
{
Log.Information("Loading settings:");
Log.Information("-----------------");

int tempInt;
bool tempBool;
try
{
int.TryParse(Properties.Settings.Default["MaxSpeed"].ToString(), out maxSpeedKBS);
trackBar1.Value = maxSpeedKBS;
Log.Information("max KBS: " + maxSpeedKBS);
int.TryParse(Properties.Settings.Default["RefreshIntervall"].ToString(), out tempInt);
timer1.Interval = tempInt;
trackBar2.Value = tempInt;
Log.Information("RefreshInterval: " + tempInt);
bool.TryParse(Properties.Settings.Default["DriveSelectedChecked"].ToString(), out tempBool);
Log.Information("SingleDrive monitoring: " + tempBool);
if (tempBool)
{
diskSelectionPFCStr = Properties.Settings.Default["DriveSelected"].ToString();
try
{
PerformanceCounterCategory tempPfcCat = new PerformanceCounterCategory("PhysicalDisk");
string[] instNames;
try
{
instNames = tempPfcCat.GetInstanceNames();

//plausi check if string is possible and drive available
bool markerFound = false;
foreach(string drv in instNames)
{
if (drv.Equals(diskSelectionPFCStr))
{
markerFound = true;
Log.Information("Successfully parsed single drive monitoring instance " + diskSelectionPFCStr);
}
}
if (markerFound == false)
{
Log.Error("Error finding monitored drive!");
throw new Exception();
}
}
catch
{
Log.Error("Error while getting physical disk list for plausi check!");
diskSelectionPFCStr = null;
tempBool = false;
}
}
catch
{
Log.Error("Error while getting physical disk category");
diskSelectionPFCStr = null;
tempBool = false;
}
}
else
{
Expand All @@ -725,19 +795,24 @@ private bool loadSettings()
iconDefault = CreateIcon(defaultColor);
tbColorDefault.BackColor = defaultColor;
tbColorDefault.Text = defaultColor.ToString();
Log.Information("ColorDefault: " + defaultColor.ToString());

readColor = ColorTranslator.FromHtml(Properties.Settings.Default["ColorRead"].ToString());
tbColorRead.BackColor = readColor;
tbColorRead.Text = readColor.ToString();
Log.Information("ColorRead: " + readColor.ToString());

writeColor = ColorTranslator.FromHtml(Properties.Settings.Default["ColorWrite"].ToString());
tbColorWrite.BackColor = writeColor;
tbColorWrite.Text = writeColor.ToString();
Log.Information("ColorWrite: " + writeColor.ToString());

Log.Information("-----------------");
return true;
}
catch (Exception)
catch
{
Log.Information("-----------------");
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions SSD-LED/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.7.0")]
[assembly: AssemblyFileVersion("1.0.7.0")]
[assembly: AssemblyVersion("1.0.7.1")]
[assembly: AssemblyFileVersion("1.0.7.1")]
5 changes: 3 additions & 2 deletions SSD-LED/SSD-LED.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<AutorunEnabled>true</AutorunEnabled>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.6.0</ApplicationVersion>
<ApplicationRevision>4</ApplicationRevision>
<ApplicationVersion>1.0.7.4</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
Expand Down Expand Up @@ -82,6 +82,7 @@
<HintPath>..\packages\Serilog.Sinks.File.5.0.0\lib\net45\Serilog.Sinks.File.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Management" />
<Reference Include="System.Windows.Forms.DataVisualization" />
Expand Down
Binary file modified SSD-LED/bin/Release/SSD-LED.exe
Binary file not shown.
Binary file added SSD-LED/bin/Release/Serilog.Sinks.File.dll
Binary file not shown.
Binary file added SSD-LED/bin/Release/Serilog.dll
Binary file not shown.

0 comments on commit a8a9696

Please sign in to comment.