private void CreateCustomActionFile(string sessionId, string customActionFile) { var sessionDirectory = GetLogsFolderForSession(sessionId); var sessionFileName = Path.Combine(sessionDirectory, customActionFile); FileSystemHelpers.AppendAllTextToFile(sessionFileName, $"Custom Action Executed on {Environment.MachineName} at {DateTime.UtcNow.ToString()} UTC"); }
private void AppendToMonitoringLog(string message, bool logInKusto = false) { Interlocked.Increment(ref _loggerCount); string cpuMonitorPath = MonitoringSessionController.GetCpuMonitoringPath(MonitoringSessionDirectories.Active); string logFilePath = Path.Combine(cpuMonitorPath, Environment.MachineName + ".log"); string logMessage = $"[{DateTime.UtcNow.ToShortDateString()} {DateTime.UtcNow.ToString("hh:mm:ss")}] {message}{Environment.NewLine}"; if (_loggerCount > MAX_LINES_IN_LOGFILE) { var sessionDirectory = GetLogsFolderForSession(_sessionId); var existingFileCount = FileSystemHelpers.GetFilesInDirectory(sessionDirectory, $"{Environment.MachineName}*.log", false, SearchOption.TopDirectoryOnly).Count; var newFileName = $"{Environment.MachineName}_{existingFileCount}.log"; newFileName = Path.Combine(sessionDirectory, newFileName); FileSystemHelpers.MoveFile(logFilePath, newFileName); Interlocked.Exchange(ref _loggerCount, 0); } try { FileSystemHelpers.AppendAllTextToFile(logFilePath, logMessage); } catch (Exception) { } if (logInKusto) { Logger.LogCpuMonitoringEvent(message, _sessionId); } }