Logger or LogWriter?

Topics: Logging Application Block
Sep 22, 2010 at 7:49 PM

Which way should I be logging?


LogWriter writer = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();
writer.Write("Log entry.");



Logger.Write("Log entry.");

Using Logger is so much easier, but all the examples I see involve getting a LogWriter instance. What's the difference, and what's the best practice for using them?


Sep 22, 2010 at 9:39 PM

You're right, Logger.Write is easier. However, we recommend using LogWriter for testability. LogWriter is an abstract base class, so you can mock it out if you need to while testing your application. If you're calling Logger.Write directly, on the other hand, then you end up having to set up a configuration file for your test. Using Logger makes things easier in the small, but complicates your overall development.