Exemplo n.º 1
0
        public void WriteLine(ILogItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }
            var level   = item.LogLevel;
            var message = item.Message;
            var phase   = item.Phase;
            var file    = item.File;
            var line    = item.Line;

            if (level < LogLevelThreshold)
            {
                return;
            }
            var now = DateTime.UtcNow.ToString("yy-MM-dd hh:mm:ss.fff");

            var formatter = $"[{now}]{level}:";

            if (!string.IsNullOrEmpty(phase))
            {
                formatter += $"[{phase}]";
            }
            if (!string.IsNullOrEmpty(file))
            {
                string lineInfo = string.Empty;
                if (!string.IsNullOrEmpty(line))
                {
                    lineInfo = $"#L{line}";
                }
                formatter += $"({file.Replace('\\', '/')}{lineInfo})";
            }

            formatter += message;

            var consoleColor = GetConsoleColor(level);

            ConsoleUtility.WriteLine(formatter, consoleColor);
        }
Exemplo n.º 2
0
 private static void WriteToConsole(string message, ConsoleColor color = ConsoleColor.White)
 {
     ConsoleUtility.WriteLine(message, color);
 }