private ServerLogFileContainer CreateContainer(string logPath) { var server = new Server() { CopyFilesToLocal = true, Name = "server", Username = "******", Password = "******", Path = "" }; var environment = new Environment() { Name = "environment" }; environment.Servers.Add(server); var appLogFiles = new List<AppLogFiles>(); appLogFiles.Add(new AppLogFiles() { LogfilePaths = { logPath }, Appname = APP_NAME }); var container = new ServerLogFileContainer(); container.Environment = environment; container.Server = server; container.AppLogFiles = appLogFiles; return container; }
private IEnumerable<AppLogFiles> GetLogfilePaths(Server server) { if (!string.IsNullOrEmpty(server.Username)) { // Net use the server LogLine("- Attempting to authenticate with {0} using {1}", server.Path, server.Username); PinvokeWindowsNetworking.ConnectToRemote(server.Path, server.Username, server.Password); } LogLine("- Searching for all .log files in {0}", server.Path); var appDictionary = new Dictionary<string, AppLogFiles>(); IEnumerable<string> paths = Directory.EnumerateFiles(server.Path, "*.log", SearchOption.AllDirectories); // Assume the parent folder of the each log file is the name of the application, // e.g. D:\ErrorLogs\MyApp\errors.log => "MyApp" foreach (string path in paths) { // Split is needed for UNC paths as Path.GetDirectoryName fails string[] parts = path.Split(Path.DirectorySeparatorChar); if (parts.Length > 1) { // e.g. "MyApp" from \\myserver\logs\MyApp\log1.log string appName = parts[parts.Length - 2]; if (appDictionary.ContainsKey(appName)) { appDictionary[appName].LogfilePaths.Add(path); } else { var appLogFile = new AppLogFiles() { Appname = appName }; appLogFile.LogfilePaths.Add(path); appDictionary.Add(appName, appLogFile); }; } } return appDictionary.Select(app => app.Value); }