Disable logging

211 views
Skip to first unread message

Riccardo Di Nuzzo

unread,
Oct 19, 2015, 11:16:00 AM10/19/15
to Particular Software
Helpful information to include
Product name: NServiceBus
Version: 5.2.8
Stacktrace:
Description: I'm using NServiceBus in an existing Console/Service process. When it starts, there are too many informations logged on the console. The app is using Log4Net for some logging and I can't change its consiguration. How I can reduce the NServiceBus logging?

I tried the following code but it doesn't work (a part that the logging is colored)

ColoredConsoleAppender appender = new ColoredConsoleAppender
            {
                Threshold = Level.Debug,
                Layout = new SimpleLayout(),
            };

            appender.AddFilter(new LoggerMatchFilter
            {
                LoggerToMatch = "NServiceBus.",
                AcceptOnMatch = false
            });
            appender.ActivateOptions();
            BasicConfigurator.Configure(appender);

            NServiceBus.Logging.LogManager.Use<Log4NetFactory>();

Thanks
Riccardo

Sean Feldman

unread,
Oct 19, 2015, 12:20:24 PM10/19/15
to Particular Software
Hi Richardo,


setting threshold to DEBUG will capture it all. Did you mean to use WARN or ERROR?

simon.cropp

unread,
Oct 19, 2015, 10:33:58 PM10/19/15
to Particular Software
Riccardo

the simplest way to filter out NSB log entries is with a custom log4net filter


Note that the filter only hides log entries below warn. I assume you still want to see important entries from NSB

As for the ColoredConsoleAppender, my understanding was you ahd to explicitly configure the color mappings. For example http://aaubry.net/configuring-log4net-coloredconsoleappender-in-code.html

Let me know if you have trouble getting those two things working together and i will have a go a putting together a full solution showing the usage and upload it somewhere

Riccardo Di Nuzzo

unread,
Oct 21, 2015, 5:31:09 AM10/21/15
to Particular Software
Thanks for the replies.

I just want to stop logging NSB info or warn on the console output. In my post you can see

appender.AddFilter(new LoggerMatchFilter
            {
                LoggerToMatch = "NServiceBus.",
                AcceptOnMatch = false
            });

for what I have understood, this stop logging. But NSB is still logging everything (but colored). I'm not interested to colors, I only want to be able to control the log level or at least stop logging.
Creating a class as a custom filter is the only way to do that?

As I already said, I guess that the problem here could be the fact that Log4net is already configured for logging other application outputs. I can't change this configuration. 

simon.cropp

unread,
Oct 21, 2015, 6:10:17 AM10/21/15
to Particular Software
Riccardo

NSB is not doing anything special with log4net
as you can see here 

As for your suggestions of using a LoggerMatchFilter, yes in theory it should work. but i tried various combinations and could not get the result you wanted. It just would not work the way i suspected.

One possible alternative is to use the FilterSkeleton i suggested and then have two different filers and two different appenders, one that filters out all NSB messages and the other that includes over a certain level.

Have you considered NLog or Serilog? I find the both cause less friction than log4net
Reply all
Reply to author
Forward
0 new messages