コード例 #1
0
 /// <summary>
 /// Creates a new instance of the <see cref="ConsoleLogStyle"/> class,
 /// for the specified settings.
 /// </summary>
 public ConsoleLogStyle(
     ConsoleLogEntryStyle informationStyle,
     ConsoleLogEntryStyle warningStyle,
     ConsoleLogEntryStyle errorStyle)
 {
     this.informationStyle = informationStyle;
     this.warningStyle     = warningStyle;
     this.errorStyle       = errorStyle;
 }
コード例 #2
0
        public void WriteEntry(ConsoleLogEntry entry, ConsoleLogEntryStyle style)
        {
            if (entry == null)
            {
                throw new ArgumentNullException(nameof(entry));
            }

            WriteEntryCore(entry.Message, entry.Source, entry.EntryType, entry.CreatedTime, style);
        }
コード例 #3
0
        private void WriteEntryCore(string message, string source, ConsoleLogEntryType type, DateTimeOffset createdTime, ConsoleLogEntryStyle style)
        {
            if (style == null)
            {
                style = GetDefaultEntryStyle(type);
            }

            lock (consoleSyncRoot)
            {
                var originalBackgroundColor = Console.BackgroundColor;
                var originalForegroundColor = Console.ForegroundColor;

                try
                {
                    if (style.BackgroundColor != null)
                    {
                        Console.BackgroundColor = (ConsoleColor)style.BackgroundColor;
                    }

                    if (style.ForegroundColor != null)
                    {
                        Console.ForegroundColor = (ConsoleColor)style.ForegroundColor;
                    }

                    if (style.MessageFormat != null)
                    {
                        writer.WriteLine(style.MessageFormat, source, message, type, createdTime);
                    }
                    else
                    {
                        if (source != null)
                        {
                            writer.Write(source);
                            writer.Write(": ");
                        }

                        writer.WriteLine(message);
                    }

                    writer.Flush();
                }
                finally
                {
                    if (style.BackgroundColor != null)
                    {
                        Console.ForegroundColor = originalForegroundColor;
                    }

                    if (style.ForegroundColor != null)
                    {
                        Console.BackgroundColor = originalBackgroundColor;
                    }
                }
            }
        }
コード例 #4
0
        public void WriteEntry(string message, string source, ConsoleLogEntryType type, DateTimeOffset createdTime, ConsoleLogEntryStyle style)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (!type.IsValid())
            {
                throw new ArgumentOutOfRangeException(nameof(type));
            }

            WriteEntryCore(message, source, type, createdTime, style);
        }
コード例 #5
0
 public ConsoleLogStyle(ConsoleLogEntryStyle entryStyle)
 {
     informationStyle = entryStyle;
     warningStyle     = entryStyle;
     errorStyle       = entryStyle;
 }