While writing a windows service, I created a console version for debugging use. I wanted this console to display all the logging, in real time, so I could see things were working. A bit of a search revealed that ColoredConsoleAppender was the desired class, so I added code to set things up.

var layout
    = new PatternLayout("%level [%thread] %d{HH:mm:ss} - %message%newline");

mConsoleLogger
    = new ColoredConsoleAppender
        {
            Name = "ConsoleAppender",
            Layout = layout,
            Threshold = Level.All
        };

var repository = (Hierarchy)LogManager.GetRepository();
repository.Root.AddAppender(mConsoleLogger);
repository.Root.Level = Level.All;

But, it didn’t work. Not at all. Back to the search engines.

Eventually, I found the (odd) solution.

Before adding the appender into the log4net repository, you need to activate it:

mConsoleLogger.ActivateOptions();

Once this is done, everything started working perfectly.

Not the way I’d write it - requiring odd incantations or other ceremony on the part of a class consumer seems fairly unfriendly.

Comments

blog comments powered by Disqus
Next Post
Windows Phone 7 vs Z88  27 Sep 2011
Prior Post
Warning MSB3247: Found conflicts between different versions of the same dependent assembly  13 Sep 2011
Related Posts
Old blog posts, restored  26 Oct 2025
Better Table Tests in Go  21 Oct 2025
Error assertions  26 Apr 2025
Browsers and WSL  31 Mar 2024
Factory methods and functions  05 Mar 2023
Using Constructors  27 Feb 2023
An Inconvenient API  18 Feb 2023
Method Archetypes  11 Sep 2022
A bash puzzle, solved  02 Jul 2022
A bash puzzle  25 Jun 2022
Archives
September 2011
2011