Beispiel #1
0
        /// <summary>
        /// Logs an entry to the Logger instance.
        /// </summary>
        /// <param name="level">The level of the entry.</param>
        /// <param name="entry">The textual value of the entry.</param>
        public override void Log(LogLevel level, object entry)
        {
            Kon.ForegroundColor = level.GetConsoleColor();
            base.Log(level, entry);
            Kon.ForegroundColor = ConsoleColor.Gray;

            // If the display level got ignored, still write it to the log
            if ((DisplayedLevels & level) == LogLevel.None)
            {
                WriteToLog($"[{level.GetHighestLevel()}] {entry}\r\n");
            }
        }
Beispiel #2
0
        private string DefaultHandleMsgFormat(Type classType, LogLevel logLevel, string msg, Exception exception, out bool outputConsole)
        {
            outputConsole = _options.LogToConsole && logLevel >= _options.MinLogLevelForConsole;

            //var result = $"[{(DateTimeFormat != null ? DateTimeFormat(DateTime.Now) : DateTime.Now.ToLongDateTimeWithTimezone())}] [{logLevel}]{(classType != null ? $" [{classType.FullName}]" : string.Empty)} => {msg}{(exception != null ? $"{Environment.NewLine}Message: {exception.Message}{Environment.NewLine}StackTrace: {exception.StackTrace}" : string.Empty)}";

            var sb = new StringBuilder();

            MsgFormatToConsole($"[{(DateTimeFormat != null ? DateTimeFormat(DateTime.Now) : DateTime.Now.ToLongDateTimeWithTimezone())}] [", sb, outputConsole);
            MsgFormatToConsole(logLevel.ToString(), sb, outputConsole, logLevel.GetConsoleColor());
            MsgFormatToConsole("]", sb, outputConsole);
            if (classType != null)
            {
                MsgFormatToConsole(" [", sb, outputConsole);
                MsgFormatToConsole(classType.FullName, sb, outputConsole, ConsoleColor.Green);
                MsgFormatToConsole("]", sb, outputConsole);
            }
            MsgFormatToConsole($" => {msg}", sb, outputConsole);
            if (exception != null)
            {
                MsgFormatToConsole(Environment.NewLine, sb, outputConsole);
                MsgFormatToConsole($"Message: {exception.Message}", sb, outputConsole, ConsoleColor.Red);
                if (!string.IsNullOrWhiteSpace(exception.StackTrace))
                {
                    MsgFormatToConsole(Environment.NewLine, sb, outputConsole);
                    MsgFormatToConsole($"StackTrace: {exception.StackTrace}", sb, outputConsole, ConsoleColor.Red);
                }
            }

            if (outputConsole)
            {
                ConsoleHelper.WriteLine();
            }

            //Console.WriteLine(sb.ToString());
            return(sb.ToString());// result
        }
Beispiel #3
0
 /// <summary>
 /// Logs an entry to the Logger instance.
 /// </summary>
 /// <param name="level">The level of the entry.</param>
 /// <param name="entry">The textual value of the entry.</param>
 public override void Log(LogLevel level, object entry)
 {
     Kon.ForegroundColor = level.GetConsoleColor();
     base.Log(level, entry);
     Kon.ForegroundColor = ConsoleColor.Gray;
 }