From df1081507d1bafc17983c73501eb03fe9d3d0a43 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 21 Jan 2021 13:17:34 -0800 Subject: [PATCH] Thrown exceptions get logged to file in Test --- Test/Program.cs | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/Test/Program.cs b/Test/Program.cs index 4d2b8775..5333939d 100644 --- a/Test/Program.cs +++ b/Test/Program.cs @@ -24,26 +24,36 @@ namespace Test foreach (string arg in args) { - var protections = scanner.GetProtections(arg); - if (protections != null) + try { - using (StreamWriter sw = new StreamWriter(File.OpenWrite($"{DateTime.Now:yyyy-MM-dd_HHmmss}.txt"))) + var protections = scanner.GetProtections(arg); + if (protections != null) { - foreach (string key in protections.Keys) + using (StreamWriter sw = new StreamWriter(File.OpenWrite($"{DateTime.Now:yyyy-MM-dd_HHmmss}.txt"))) { - // Skip over files with no protection - if (protections[key] == null || !protections[key].Any()) - continue; + foreach (string key in protections.Keys) + { + // Skip over files with no protection + if (protections[key] == null || !protections[key].Any()) + continue; - string line = $"{key}: {string.Join(", ", protections[key])}"; - Console.WriteLine(line); - sw.WriteLine(line); + string line = $"{key}: {string.Join(", ", protections[key])}"; + Console.WriteLine(line); + sw.WriteLine(line); + } } } + else + { + Console.WriteLine($"No protections found for {arg}"); + } } - else + catch (Exception ex) { - Console.WriteLine($"No protections found for {arg}"); + using (StreamWriter sw = new StreamWriter(File.OpenWrite($"{DateTime.Now:yyyy-MM-dd_HHmmss}-exception.txt"))) + { + sw.WriteLine(ex.Message); + } } }