public void Write(LogEntry entry) { switch (entry.Category) { case EntryCategory.Information: Console.ForegroundColor = ConsoleColor.Green; Console.Out.WriteLine(entry.ToString()); break; case EntryCategory.Warning: Console.ForegroundColor = ConsoleColor.Yellow; Console.Out.WriteLine(entry.ToString()); Console.Error.WriteLine(entry.ToString()); break; case EntryCategory.Error: Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine(entry.ToString()); break; default: break; } Console.WriteLine(Environment.NewLine); }
private void AddEntry(LogEntry entry) { string entryString = entry.ToString(); int breakPoint = entryString.IndexOf(Environment.NewLine); string[] lines; TreeNode subnode; TreeNode node = new TreeNode(entryString.Substring(0, (breakPoint >= 0)?breakPoint:entryString.Length)); node.Tag = entry; node.ContextMenuStrip = logStrip; switch (entry.Category) { case EntryCategory.Information: node.ImageKey = "information.png"; node.ForeColor = Color.Green; break; case EntryCategory.Warning: node.ImageKey = "warnings.png"; node.ForeColor = Color.DarkGoldenrod; break; case EntryCategory.Error: node.ImageKey = "errors.png"; node.ForeColor = Color.Red; break; default: throw new Exception("Invalid value for EntryCategory"); } if (breakPoint >= 0) { lines = entryString.Remove(0, breakPoint).Split(new string[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries); foreach (string line in lines) { subnode = new TreeNode(line); subnode.ImageKey = node.ImageKey; subnode.ForeColor = node.ForeColor; node.Nodes.Add(subnode); } } logTree.Nodes.Add(node); }