Skip to content

Commit 4cfbfe2

Browse files
SQLCheck added exception handler
1 parent f1de08f commit 4cfbfe2

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

SQLCheck/SQLCheck/Collectors.cs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -367,18 +367,28 @@ public static void CollectComputer(DataSet ds)
367367
// Addition - Adding Last system reboot time // Clintonw 9/8/2022 Issue #42
368368
// Based on Event 12 "Microsoft-Windows-Kernel-General"
369369
EventLog SystemEventLog = new EventLog("System", ".");
370-
EventLogEntryCollection LogEntryCollection = SystemEventLog.Entries;
371-
int LogEntriesCount = LogEntryCollection.Count;
372-
for (int i = LogEntriesCount - 1; i > -1; i--)
373-
{
374-
EventLogEntry LogEntry = LogEntryCollection[i];
375-
if (LogEntry.EntryType.ToString().Equals("Information") && LogEntry.Source == "Microsoft-Windows-Kernel-General" && LogEntry.InstanceId == 12)
376-
{ // Console.WriteLine(LogEntry.Source + LogEntry.EntryType + LogEntry.Message + LogEntry.TimeGenerated);
377-
Computer["LastSystemReboot"] = LogEntry.TimeGenerated; // Uptime: days, hours, min
378-
break;
370+
try
371+
{
372+
EventLogEntryCollection LogEntryCollection = SystemEventLog.Entries;
373+
int LogEntriesCount = LogEntryCollection.Count;
374+
for (int i = LogEntriesCount - 1; i > -1; i--)
375+
{
376+
EventLogEntry LogEntry = LogEntryCollection[i];
377+
if (LogEntry.EntryType.ToString().Equals("Information") && LogEntry.Source == "Microsoft-Windows-Kernel-General" && LogEntry.InstanceId == 12)
378+
{ // Console.WriteLine(LogEntry.Source + LogEntry.EntryType + LogEntry.Message + LogEntry.TimeGenerated);
379+
Computer["LastSystemReboot"] = LogEntry.TimeGenerated; // Uptime: days, hours, min
380+
break;
381+
}
379382
}
380-
}
381-
SystemEventLog.Close();
383+
}
384+
catch (Exception ex)
385+
{
386+
Computer.LogException($@"Failure to read last reboot information from the System event log.", ex);
387+
}
388+
finally
389+
{
390+
if (SystemEventLog != null) SystemEventLog.Close();
391+
}
382392

383393
}
384394

SQLCheck/SQLCheck/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.1256.0")]
36-
[assembly: AssemblyFileVersion("1.0.1256.0")]
35+
[assembly: AssemblyVersion("1.0.1257.0")]
36+
[assembly: AssemblyFileVersion("1.0.1257.0")]
0 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)