/// <summary> /// read file from directory /// </summary> public void ReadFiles() { foreach (string filePath in FilePaths) { LogFiles.Add(new LogFile(filePath)); } }
/// <summary> /// Gets the log files from the server (using webclient). /// </summary> /// <param name="server">The server.</param> /// <param name="directory">The directory.</param> /// <returns></returns> /// <author>Jurie.smit</author> /// <date>2013/05/24</date> public IEnumerable <FilePath> GetLogFiles(IEnvironmentModel server, DirectoryPath directory) { LogFiles.Clear(); if (server == null || directory == null) { return(new List <FilePath>()); } var address = String.Format(server.Connection.WebServerUri + "{0}/{1}?DirectoryPath={2}", "Services", "FindDirectoryService", directory.PathToSerialize); var datalistJson = WebClient.UploadString(address, string.Empty); if (datalistJson.Contains("Error")) { var error = "Error: Log directory not found." + Environment.NewLine + datalistJson.GetManagementPayload(); ShowErrorPopup(error); } else { var filePaths = JsonConvert.DeserializeObject <List <FilePath> >(datalistJson); filePaths.ForEach(fp => { if (fp.Title.EndsWith(".wwlfl")) { LogFiles.Add(fp); } }); return(filePaths); } return(new List <FilePath>()); }
/// <summary> /// 更新最新日志文件信息 /// </summary> /// <param name="path"></param> public static void UpdateLastCreateFileInfo(string path) { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); return; } var directory = new DirectoryInfo(path); var files = directory.GetFiles().ToList(); foreach (var file in files) { LogFiles.Add(file.Name); } files = files.OrderByDescending(f => f.CreationTimeUtc).ToList(); foreach (var levelName in LevelNames.Values) { var level = NameLevels[levelName]; foreach (var fileInfo in files) { if (fileInfo.Name.Contains(levelName)) { LastCreateFileNames[level] = fileInfo.Name; LastCreateFileSize[level] = fileInfo.Length; LastCreateFileTime[level] = fileInfo.CreationTimeUtc; break; } } } }
/// <summary> /// Updates the log folder's in-memory collection of <see cref="LogFile"/>s. /// </summary> private void LoadLogFilesAsync() { Task.Run(() => { AppInfo.BaseAppInfo.Log.QueueLogMessageAsync($"Loading log files for log folder with path \"{Folder.FullName}\".", LogMessageType.Verbose); Folder?.Refresh(); var logFolderExists = Folder.Exists; try { //Get list of log file names that are already loaded var currentLogFileNames = new List <string>(); foreach (var logFile in LogFiles) { currentLogFileNames.Add(logFile.NetworkFile.FullName); } foreach (var file in Folder.GetFiles()) { if (!currentLogFileNames.Contains(file.FullName)) { AppInfo.BaseAppInfo.Log.QueueLogMessageAsync($"Adding log file with name: \"{file.Name}\" to log folder with path \"{Folder.FullName}\".", LogMessageType.Verbose); LogFiles.Add(new LogFile(file.FullName, this)); } } } catch (DirectoryNotFoundException) { logFolderExists = false; } catch (IOException) { logFolderExists = false; } if (!logFolderExists) { HasError = true; Notification = new Notification(this, $"Could not find log folder with path \"{Folder.FullName}\"."); AppInfo.BaseAppInfo.Log.QueueLogMessageAsync(Notification.Message, LogMessageType.Error); } else { AppInfo.BaseAppInfo.Log.QueueLogMessageAsync($"Found {LogFiles.Count} log files in log folder with path \"{Folder.FullName}\".", LogMessageType.Verbose); } }); }
private void SetupExceptionHandler() { // initialize exception handler ExceptionHandler.AppName = "BugTrapNetTest"; ExceptionHandler.Flags = FlagsType.DetailedMode | FlagsType.ScreenCapture | FlagsType.AttachReport | FlagsType.EditMail; ExceptionHandler.ReportFormat = ReportFormatType.Xml; ExceptionHandler.DumpType = MinidumpType.NoDump; ExceptionHandler.SupportEMail = "*****@*****.**"; ExceptionHandler.SupportURL = "http://www.intellesoft.net"; ExceptionHandler.SupportHost = "localhost"; ExceptionHandler.SupportPort = 9999; // register custom log file this.log = new LogFile("test.log", LogFormatType.Xml); LogFiles.Add(new LogFileEntry(this.log.FileName)); this.log.LogSizeInEntries = 3; }
private void FileSystemWatcher_Created(object sender, FileSystemEventArgs e) { LogFiles.Add(new LogFile(new FileInfo(e.FullPath))); SortLogFiles(); }