diff --git a/ATxCommon/SystemChecks.cs b/ATxCommon/SystemChecks.cs index e0ce3a3ebae629dd1c6bcb071126ec89b542e258..7f8231ba8a425a51ef2b755b32d48e6abcb401ff 100644 --- a/ATxCommon/SystemChecks.cs +++ b/ATxCommon/SystemChecks.cs @@ -115,5 +115,39 @@ namespace ATxCommon return username == ""; } + + /// <summary> + /// Log names of running processes if loglevel is set to debug. + /// </summary> + /// <param name="longFormat">By default only the process names will be printed to the + /// log, enclosed by square brackets (e.g. [explorer]). If "longFormat" is set to true, + /// each process name will be printed on a separate line, followed by the title of the + /// corresponding main window (if existing).</param> + public static void LogRunningProcesses(bool longFormat=false) { + if (!Log.IsDebugEnabled) + return; + + if (longFormat) + Log.Debug("\n\n>>>>>>>>>>>> running processes >>>>>>>>>>>>"); + + var procs = ""; + foreach (var running in Process.GetProcesses()) { + if (longFormat) { + var title = running.MainWindowTitle; + if (title.Length > 0) { + title = " (\"" + title + "\")"; + } + Log.Debug(" - {0}{1}", running.ProcessName, title); + } else { + procs += $", [{running.ProcessName}]"; + } + } + + if (longFormat) { + Log.Debug("\n<<<<<<<<<<<< running processes <<<<<<<<<<<<\n"); + } else { + Log.Debug("Currently running processes: {0}", procs.Substring(2)); + } + } } } diff --git a/ATxDiagnostics/ATxDiagnostics.cs b/ATxDiagnostics/ATxDiagnostics.cs index 31de4c48f4bf0e26de11ad2f5ed63ca528d0b608..e47c2fc64ada71b47282158af63c0e091b035e44 100644 --- a/ATxDiagnostics/ATxDiagnostics.cs +++ b/ATxDiagnostics/ATxDiagnostics.cs @@ -41,15 +41,7 @@ namespace ATxDiagnostics Log.Debug("Free space on drive [C:]: " + Conv.BytesToString(SystemChecks.GetFreeDriveSpace("C:"))); - Log.Debug("\n\n>>>>>>>>>>>> running processes >>>>>>>>>>>>"); - foreach (var running in Process.GetProcesses()) { - var title = running.MainWindowTitle; - if (title.Length > 0) { - title = " (\"" + title + "\")"; - } - Log.Debug(" - {0}{1}", running.ProcessName, title); - } - Log.Debug("\n<<<<<<<<<<<< running processes <<<<<<<<<<<<\n"); + SystemChecks.LogRunningProcesses(true); if (perfMonitors.Contains("CPU")) { Log.Info("Watching CPU load using ATxCommon.Monitoring...");