/// <summary> /// Waits appearance of the first folder in the collection data folder /// </summary> public static Task WaitStartCollectData(Logcfg logcfg) { var tcs = new TaskCompletionSource <bool>(); var logPaths = logcfg.GetLogPaths(); FileSystemWatcher[] watchers = new FileSystemWatcher[logPaths.Length]; for (int x = 0; x < logPaths.Length; x++) { var watcher = new FileSystemWatcher { NotifyFilter = NotifyFilters.DirectoryName, Path = logPaths[x], Filter = "*" }; watcher.Created += (sender, args) => { watchers.ToList().ForEach(c => c.EnableRaisingEvents = false); tcs.TrySetResult(true); watchers.ToList().ForEach(c => c.Dispose()); }; watchers[x] = watcher; } watchers.ToList().ForEach(c => c.EnableRaisingEvents = true); return(tcs.Task); }
/// <summary> /// Returns paths of the log files /// </summary> /// <param name="logcfg">Logcfg instance</param> /// <returns></returns> public static string[] GetLogFiles(Logcfg logcfg) { List <string> files = new List <string>(); foreach (var path in logcfg.GetLogPaths()) { files.AddRange(Directory.GetFiles(path, "*.log", SearchOption.AllDirectories)); } return(files.Distinct().ToArray()); }
/// <summary> /// Initializes the _logcfg variable /// </summary> private void InitializeLogCfg() { _logcfg = new Logcfg(_settings); _logcfg.AddLog(TlHelper.GetCollectPeriod(_settings.CollectPeriod).ToString(), _settings.TlFolder); _logcfg.AddEvent(Logcfg.DBMSSQL_EV); _logcfg.AddProperty(Logcfg.USER_PR); _logcfg.AddProperty(Logcfg.CONTEXT_PR); _logcfg.AddProperty(Logcfg.CONNECT_ID_PR); _logcfg.AddProperty(Logcfg.SQL_PR); _logcfg.AddProperty(Logcfg.CLIENT_ID_PR); if (_settings.FilterByDatabase) { _logcfg.AddFilter(Logcfg.EQ_CT, Logcfg.PROCESS_NAME_PR, _settings.Database1C); } if (_settings.FilterByDuration) { _logcfg.AddFilter(Logcfg.GE_CT, Logcfg.DURATION_PR, _settings.Duration.ToString()); } }