2

I use NLog in my application. I have facade Logging that has private static Logger, so there is just one Logger in entire application. Like this:

 public class Logging
 {
        private static Logger _logger;
        //... constructors and methods
 }

But I read in Nlog documentation that 'one logger per class' approach is recommended, so you easily get point exception came from. So each class would have:

private static Logger _logger;

But that way every class would be coupled to NLog's Logger and LogManager class. What is best way to implement 'one logger per class' in this situation?

bambi
  • 1,159
  • 2
  • 14
  • 31
  • See http://stackoverflow.com/questions/3143929/why-do-loggers-recommend-using-a-logger-per-class?rq=1 – Julian Jan 27 '16 at 12:11

1 Answers1

2

If you don't create a logger for each class, then you can't filter easily the messages in the config. Also if you use a helper class, then is still (indirect) coupled?

You can decouple NLog by using Common Logging. I has some up- and downsides, see faq.

Julian
  • 33,915
  • 22
  • 119
  • 174