Example #1
0
        private static void AddHighlightingRules(List <string> words, bool isRegEx = false)
        {
            var target = (ColoredConsoleTarget)LogManager.Configuration.FindTargetByName("console");
            var rule   = target.WordHighlightingRules.FirstOrDefault();

            var bgColor = ConsoleOutputColor.Green;
            var fgColor = ConsoleOutputColor.Red;

            if (rule != null)
            {
                bgColor = rule.BackgroundColor;
                fgColor = rule.ForegroundColor;
            }

            foreach (var word in words)
            {
                var r = new ConsoleWordHighlightingRule {
                    IgnoreCase = true
                };
                if (isRegEx)
                {
                    r.Regex = word;
                }
                else
                {
                    r.Text = word;
                }
                r.ForegroundColor = fgColor;
                r.BackgroundColor = bgColor;

                r.WholeWords = false;
                target.WordHighlightingRules.Add(r);
            }
        }
 /// <summary>
 /// Adds the elements of an array to the end of this ConsoleWordHighlightingRuleCollection.
 /// </summary>
 /// <param name="items">
 /// The array whose elements are to be added to the end of this ConsoleWordHighlightingRuleCollection.
 /// </param>
 public virtual void AddRange(ConsoleWordHighlightingRule[] items)
 {
     foreach (ConsoleWordHighlightingRule item in items)
     {
         this.List.Add(item);
     }
 }
Example #3
0
    private static void SetupNLog()
    {
        if (File.Exists("Nlog.config"))
        {
            return;
        }

        var config   = new LoggingConfiguration();
        var loglevel = LogLevel.Info;

        var layout = @"${message}";

        var consoleTarget = new ColoredConsoleTarget();

        var whr = new ConsoleWordHighlightingRule("this will be replaced with search term", ConsoleOutputColor.Red,
                                                  ConsoleOutputColor.Green);

        consoleTarget.WordHighlightingRules.Add(whr);

        config.AddTarget("console", consoleTarget);

        consoleTarget.Layout = layout;

        var rule1 = new LoggingRule("*", loglevel, consoleTarget);

        config.LoggingRules.Add(rule1);

        LogManager.Configuration = config;
    }
Example #4
0
        public void CompiledRegexPropertyNotNull(bool compileRegex)
        {
            var rule = new ConsoleWordHighlightingRule
            {
                ForegroundColor = ConsoleOutputColor.Red,
                Regex           = "\\wat",
                CompileRegex    = compileRegex
            };

            Assert.NotNull(rule.CompiledRegex);
        }
Example #5
0
        //
        // Add to the default logging configuration for rules displaying
        // logs on the console.
        //
        protected void SetUpConsole(LoggingConfiguration config)
        {
            ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget();

            string targetName = "console";

            config.AddTarget(targetName, consoleTarget);

            consoleTarget.Layout =
                @"${longdate} ${pad:padding=5:inner=-${uppercase:${level}}-} ${message}";

            LoggingRule consoleRule = new LoggingRule(
                "*",
//                 LogLevel.Trace,
//                 LogLevel.Debug,
                LogLevel.Info,
                consoleTarget);

            config.LoggingRules.Add(consoleRule);

            consoleTarget.UseDefaultRowHighlightingRules = false;

            ConsoleWordHighlightingRule debugHighlightRule =
                new ConsoleWordHighlightingRule(
                    "-DEBUG-",
                    ConsoleOutputColor.DarkBlue,
                    ConsoleOutputColor.Yellow);

            ConsoleWordHighlightingRule infoHighlightRule =
                new ConsoleWordHighlightingRule(
                    "-INFO-",
                    ConsoleOutputColor.DarkGreen,
                    ConsoleOutputColor.Black);

            ConsoleWordHighlightingRule warnHighlightRule =
                new ConsoleWordHighlightingRule(
                    "-WARN-",
                    ConsoleOutputColor.DarkYellow,
                    ConsoleOutputColor.Black);

            ConsoleWordHighlightingRule errorHighlightRule =
                new ConsoleWordHighlightingRule(
                    "-ERROR-",
                    ConsoleOutputColor.Yellow,
                    ConsoleOutputColor.DarkMagenta);

            ConsoleWordHighlightingRule fatalHighlightRule =
                new ConsoleWordHighlightingRule(
                    "-FATAL-",
                    ConsoleOutputColor.White,
                    ConsoleOutputColor.DarkRed);

            consoleTarget.WordHighlightingRules.Add(debugHighlightRule);

            consoleTarget.WordHighlightingRules.Add(infoHighlightRule);

            consoleTarget.WordHighlightingRules.Add(warnHighlightRule);

            consoleTarget.WordHighlightingRules.Add(errorHighlightRule);

            consoleTarget.WordHighlightingRules.Add(fatalHighlightRule);
        }
 /// <summary>
 /// Removes the first occurrence of a specific ConsoleWordHighlightingRule from this ConsoleWordHighlightingRuleCollection.
 /// </summary>
 /// <param name="value">
 /// The ConsoleWordHighlightingRule value to remove from this ConsoleWordHighlightingRuleCollection.
 /// </param>
 public virtual void Remove(ConsoleWordHighlightingRule value)
 {
     this.List.Remove(value);
 }
 /// <summary>
 /// Initializes a new instance of the ConsoleWordHighlightingRuleCollection class, containing elements
 /// copied from an array.
 /// </summary>
 /// <param name="items">
 /// The array whose elements are to be added to the new ConsoleWordHighlightingRuleCollection.
 /// </param>
 public ConsoleWordHighlightingRuleCollection(ConsoleWordHighlightingRule[] items)
 {
     this.AddRange(items);
 }
 /// <summary>
 /// Inserts an element into the ConsoleWordHighlightingRuleCollection at the specified index
 /// </summary>
 /// <param name="index">
 /// The index at which the ConsoleWordHighlightingRule is to be inserted.
 /// </param>
 /// <param name="value">
 /// The ConsoleWordHighlightingRule to insert.
 /// </param>
 public virtual void Insert(int index, ConsoleWordHighlightingRule value)
 {
     this.List.Insert(index, value);
 }
 /// <summary>
 /// Return the zero-based index of the first occurrence of a specific value
 /// in this ConsoleWordHighlightingRuleCollection
 /// </summary>
 /// <param name="value">
 /// The ConsoleWordHighlightingRule value to locate in the ConsoleWordHighlightingRuleCollection.
 /// </param>
 /// <returns>
 /// The zero-based index of the first occurrence of the _ELEMENT value if found;
 /// -1 otherwise.
 /// </returns>
 public virtual int IndexOf(ConsoleWordHighlightingRule value)
 {
     return this.List.IndexOf(value);
 }
 /// <summary>
 /// Determines whether a specfic ConsoleWordHighlightingRule value is in this ConsoleWordHighlightingRuleCollection.
 /// </summary>
 /// <param name="value">
 /// The ConsoleWordHighlightingRule value to locate in this ConsoleWordHighlightingRuleCollection.
 /// </param>
 /// <returns>
 /// true if value is found in this ConsoleWordHighlightingRuleCollection;
 /// false otherwise.
 /// </returns>
 public virtual bool Contains(ConsoleWordHighlightingRule value)
 {
     return this.List.Contains(value);
 }
 /// <summary>
 /// Adds an instance of type ConsoleWordHighlightingRule to the end of this ConsoleWordHighlightingRuleCollection.
 /// </summary>
 /// <param name="value">
 /// The ConsoleWordHighlightingRule to be added to the end of this ConsoleWordHighlightingRuleCollection.
 /// </param>
 public virtual void Add(ConsoleWordHighlightingRule value)
 {
     this.List.Add(value);
 }
Example #12
0
        private static void AddHighlightingRules(List<string> words, bool isRegEx = false)
        {
            var target = (ColoredConsoleTarget) LogManager.Configuration.FindTargetByName("console");
            var rule = target.WordHighlightingRules.FirstOrDefault();

            var bgColor = ConsoleOutputColor.Green;
            var fgColor = ConsoleOutputColor.Red;

            if (rule != null)
            {
                bgColor = rule.BackgroundColor;
                fgColor = rule.ForegroundColor;
            }

            target.WordHighlightingRules.Clear();

            foreach (var word in words)
            {
                var r = new ConsoleWordHighlightingRule();
                r.IgnoreCase = true;
                if (isRegEx)
                {
                    r.Regex = word;
                }
                else
                {
                    r.Text = word;
                }
                r.ForegroundColor = fgColor;
                r.BackgroundColor = bgColor;

                r.WholeWords = false;
                target.WordHighlightingRules.Add(r);
            }
        }