private static void WriteLogInFile(ShutdownType shutdownType, ShutdownOptions shutdownOptions, string pathToLogDirectory) { if (!string.IsNullOrEmpty(pathToLogDirectory)) { var filePath = $@"{pathToLogDirectory}\{DateTime.Now.ToString("dd-MM-yyyy")}.log"; //path to log file if (!File.Exists(filePath)) //if file is not exists { var createdFile = File.Create(filePath); //create it createdFile.Close(); //close created file to free process } using (var textWriter = new StreamWriter(filePath)) { textWriter.WriteLine($"{DateTime.Now} - {shutdownType.ToString()} - {shutdownOptions.ToString()}"); } } }