コード例 #1
0
        /// <summary>
        /// Appends the given message to the logfile, using the specified settings.
        /// </summary>
        public override void Log(LogMessage message, LoggerSettings settings)
        {
            StringBuilder builder = new StringBuilder();

            if (settings.IncludeDate)
            {
                builder.Append($"{Date.ToString(settings.DateFormat)} ");
            }
            if (settings.IncludeTime)
            {
                builder.Append($"{Date.ToString(settings.TimeFormat)} ");
            }
            if (settings.IncludeDate || settings.IncludeTime)
            {
                builder.Append(' ');
            }

            builder.Append(message.Level.ToString().PadRight(7));

            if (message.SenderType != null)
            {
                builder.Append($"{FormatTypeName(message.SenderType)}: ");
            }

            int left = builder.Length;

            builder.Append(message.Message);

            if (!string.IsNullOrEmpty(message.AdditionalInfo))
            {
                foreach (string line in message.AdditionalInfo.Split('\n'))
                {
                    builder.AppendLine();
                    builder.Append(' ', left);
                    builder.Append(line);
                }
            }

            _streamWriter.WriteLine(builder.ToString());
        }
コード例 #2
0
        /// <summary>
        /// Logs the specified message to the console, using the given logger settings.
        /// </summary>
        public override void Log(LogMessage message, LoggerSettings settings)
        {
            if (settings.IncludeDate)
            {
                Console.Write($"{Date.ToString(settings.DateFormat)} ");
            }
            if (settings.IncludeTime)
            {
                Console.Write($"{Date.ToString(settings.TimeFormat)} ");
            }
            if (settings.IncludeDate || settings.IncludeTime)
            {
                Console.Write(' ');
            }

            WriteLogLevel(message.Level);
            Console.Write("  ");

            if (message.SenderType != null)
            {
                Console.ForegroundColor = ConsoleColor.DarkGray;
                Console.Write($"{FormatTypeName(message.SenderType)}: ");
                Console.ResetColor();
            }

            int left = Console.CursorLeft;

            Console.WriteLine(message.Message);

            if (!string.IsNullOrEmpty(message.AdditionalInfo))
            {
                foreach (string line in message.AdditionalInfo.Split('\n'))
                {
                    Console.CursorLeft = left;
                    Console.WriteLine(line);
                }
            }
        }
コード例 #3
0
ファイル: LogOutput.cs プロジェクト: yiliansource/chesster
 /// <summary>
 /// Logs the specified message, using the specified settings.
 /// </summary>
 public abstract void Log(LogMessage message, LoggerSettings settings);