private static void UpdateLogList(TreeNodeCollection nodes, string targetServer = null) { if (Logs == null) { Logs = new StringNode(null); // Add standard nodes StringNode std = new StringNode(EditorProperties.Resources.EventLogParentStandard); string[] stdLogs = new string[] { "Application", "Security", "Setup", "System", "ForwardedEvents" }; foreach (string s in stdLogs) { std.Nodes.Add(new StringNode(s, s)); } std.LastChild.Text = "Forwarded Events"; Logs.Nodes.Add(std); // Get all event logs and remove standard ones var list = new List <string>(SystemEventEnumerator.GetEventLogs(targetServer)); list.Sort(); foreach (string s in stdLogs) { list.Remove(s); } // Add app nodes StringNode lastParent = null, curCompare = null, appNode = new StringNode(EditorProperties.Resources.EventLogParentApps); Logs.Nodes.Add(appNode); int max = 0; var partList = list.ConvertAll <string[]>(delegate(string s) { var a = s.Split('-', '/', '\\'); max = Math.Max(max, a.Length); return(a); }); for (int i = 0; i < partList.Count; i++) { lastParent = appNode; for (int j = 0; j < partList[i].Length; j++) { if (curCompare != null && string.Compare(curCompare, partList[i][j], true) == 0) { lastParent = curCompare; curCompare = curCompare.LastChild; } else { var sn = new StringNode(partList[i][j]); if (j == partList[i].Length - 1) { sn.Path = list[i]; } lastParent.Nodes.Add(sn); lastParent = sn; } } curCompare = appNode.LastChild; } } Logs.UpdateTreeView(nodes); }