0

Folks,

I got NServiceBus logging working correctly following the directions found here: http://docs.particular.net/nservicebus/logging/

However, I am using Common.Logging. If I use the LogManager for Common.Logging, it doesn't log.

If I use the LogManager for log4net, everything works just fine.

Anyone have any insight here?

Simon
  • 33,714
  • 21
  • 133
  • 202
CubanX
  • 5,176
  • 2
  • 29
  • 44

3 Answers3

3

I figured this out. I needed to programatically set up Common.Logging instead of declaratively (in the config file).

Basically, I added this line before I did my fluent bus configuration:

    LogManager.Adapter = new Log4NetLoggerFactoryAdapter(new NameValueCollection { { "configType", "INLINE" } });
    SetLoggingLibrary.Log4Net(log4net.Config.XmlConfigurator.Configure);

And my bus logging section looks like this:

.Log4Net<ColoredConsoleAppender>(cca =>
                                                 {
                                                    cca.Layout = patternLayout;
                                                 })
.Log4Net<RollingFileAppender>(fa =>
                                              {
                                                fa.File = "log/handler.log";
                                                fa.AppendToFile = true;
                                                fa.RollingStyle = RollingFileAppender.RollingMode.Size;
                                                fa.MaxSizeRollBackups = 5;
                                                fa.MaximumFileSize = "1000KB";
                                                fa.StaticLogFileName = true;
                                                fa.Layout = patternLayout;
                                              })

This allows me to load the logging levels in the config file, but leave the appender configuration in code as suggested by Udi (and I think it's a great idea)

I know I could of used the built in logging level of nServiceBus, but I couldn't figure out how to get fine grained control of that so that I could ignore nHibernate logging, but get all of the nServiceBus logging.

If anyone needs more guidance as to what I did, just comment here, or if you know how to get fine grained control using the nServiceBus logging level, let me know that too.

CubanX
  • 5,176
  • 2
  • 29
  • 44
0

As of NServiceBus 5 CommonLogging is supported OOTB http://docs.particular.net/nservicebus/logging/common-logging

Simon
  • 33,714
  • 21
  • 133
  • 202
0

Common.Logging serves as an abstraction from log4net for the internal purposes of NServiceBus.

Udi Dahan
  • 11,932
  • 1
  • 27
  • 35
  • Right, I noticed in your blog you guys are using Common.Logging internally. I'm also using it in my project. Is there any way I can get the two lined up so I can use Common.Logging inside Handlers and I see the actual log messages in my log file when using Common.Logging? – CubanX May 11 '11 at 12:25
  • You'd have to use the core-only binaries and reference the same DLL as that which comes with NServiceBus. – Udi Dahan May 13 '11 at 19:03