#region Unpack server log files and combine:
string root = Environment.ExpandEnvironmentVariables(@"C:\\data\\raw_logs"); if (Directory.Exists(root)) this.WriteToLog(String.Format("Root found: {0} {1}", root, Environment.NewLine)); else { this.WriteToLog(String.Format("Root not found: {0} {1}", root, Environment.NewLine)); return; }
string zipExe = Environment.ExpandEnvironmentVariables(@"%ProgramFiles%\\7-Zip\\7z.exe"); string zipExeArgs = @"e -tother -o{0} {1}"; if (File.Exists(zipExe)) this.WriteToLog(String.Format("Archive utility found: {0} {1}", zipExe, Environment.NewLine)); else { this.WriteToLog(String.Format("Archive utility not found: {0} {1}", zipExe, Environment.NewLine)); return; }
string archiveTmpFolder = Environment.ExpandEnvironmentVariables(@"C:\\data\\raw_logs\\out"); if (Directory.Exists(archiveTmpFolder)) this.WriteToLog(String.Format("Archive temp folder found: {0} {1}", archiveTmpFolder, Environment.NewLine)); else { this.WriteToLog(String.Format("Archive temp folder not found: {0} {1}", archiveTmpFolder, Environment.NewLine)); return; }
foreach (string p in Directory.GetFiles(root)) { if (p.Contains(".gz")) { this.WriteToLog(String.Format("Extracting {0}…{1}", p, Environment.NewLine)); ProcessStartInfo info = new ProcessStartInfo(zipExe); info.Arguments = String.Format(zipExeArgs, archiveTmpFolder, p); info.CreateNoWindow = true; info.UseShellExecute = false; Process.Start(info); } else if (p.Contains("access.log.")) File.Copy(p, String.Concat(archiveTmpFolder, String.Concat(archiveTmpFolder, @"\\", IO.FileName(p)))); }
string combineCommand = String.Format(@"copy {0}\\access* {1}\\log.txt", archiveTmpFolder, root); this.WriteToLog(String.Format("Copying and combining log file data…{0}", Environment.NewLine)); this.WriteToLog(String.Format("{0}{1}", Diagnostics.RunConsoleCommand(combineCommand), Environment.NewLine));
this.WriteToLog(String.Format("Clearing archive temp folder…{0}", Environment.NewLine)); this.WriteToLog(String.Format("{0}{1}", Diagnostics.RunConsoleCommand(String.Format(@"del /q {0}\\access*", archiveTmpFolder)), Environment.NewLine));
#endregion