Skip to content

viviab/ConsoleLogger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

# Readme.md

Console app and logger: Good practices

  • Net Framework 4.7
  • Unity (resolver container)
  • log4net library (v2.0.5)

This repository contains the simple solution to easy configure a logger in your console apps (valid for web apps as well) and we resolve the dependency injection for unit and integration tests.

define Logger as static

    public static class Logger
    {
        public static ILog Log { get; set; }

    }

initializated in the Bootstrap class

        internal static void Init()
        {
            ConfigLogger();
            Logger.Log.Info("Init!");

            _container = new UnityContainer();
            _container.MyDependencyInjection();
        }

        internal static void ConfigLogger()
        {
            XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.BaseDirectory + Log4NetConfigFileName));
            Logger.Log = LogManager.GetLogger("AppLogger");
        }

We´ve separated the initization of our Logger and the dependencies of our project.

In the test layer we might use a mock of the Logger:

        private ILog _mockLog;

        [SetUp]
        public void Setup()
        {
            _mockLog = MockRepository.GenerateMock<ILog>();
            _mockLog.Expect(e => e.Debug(Arg<object>.Is.Anything)).Repeat.Once();
            Logger.Log = _mockLog;

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages