Skip to content

Autofac Module that integrating Autofac and NLog, it supports both constructor and property injection.

License

Notifications You must be signed in to change notification settings

structre40/Autofac.Extras.NLog

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

##Autofac Loggging Module for NLog

Build status

Nuget package available, to install run the following command;

Install-Package Autofac.Extras.NLog

###Register NLogModule to Autofac

It attaches to Component Registration and creates logger for requested type.

containerBuilder.RegisterModule<NLogModule>();

###Register SimpleNLogModule to Autofac It is useful when ILogger resolved from Service Locator.

containerBuilder.RegisterModule<SimpleNLogModule>();

####NLogModule and SimpleNLogModule supports both constructor and property injection.

  • Constructor sample
public class SampleClassWithConstructorDependency : ISampleInterface
{
    private readonly ILogger _logger;

    public SampleClassWithConstructorDependency(ILogger logger)
    {
      _logger = logger;
  }        
}
  • Property Sample
public class SampleClassWithPropertyDependency : ISampleInterface
{
   public ILogger Logger { get; set; }
}
  • Service Locator Sample
 public class SampleClassToResolveLoggerFromServiceLocator : ISampleClass
    {
        private readonly ILogger _logger;
        
        public SampleClassToResolveLoggerFromServiceLocator(ILifetimeScope serviceLocator)
        {
            _logger = serviceLocator.Resolve<ILogger>();
        }
    }

About

Autofac Module that integrating Autofac and NLog, it supports both constructor and property injection.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • C# 100.0%