Git Product home page Git Product logo

autofac.log4net's Introduction

Autofac.log4net

Description

Autofac.log4net is a library that allows easy integration of log4net with the Autofac IoC container. It contains a Log4NetModule to support injection of ILog properties and constructor parameter to instances created through the Autofac container. The library now supports .net core (which is awesome!).

VisualStudioBuild NuGet version

Requirements

  • Supports .NET 4 and above.
  • The package has 2 package dependencies:
    • log4net >= 2.0.3
    • Autofac >= 3.0.0

Features

  • If a class has a property or constructor parameter of type ILog, it will inject it with a logger.
    • The logger instance will be by default the logger with the class type name.
    • If the type/namespace of the class is mapped in the module, the logger instance will be the mapped logger.
  • There are 2 type of mappings the Log4NetModule:
    1. Mapping by types.
    2. Mapping by namespaces - when injecting the logger, the most specific namespace mapping will be used.
  • The module allows configuring the application to a custom logger configuration file and watching it.

License:

MIT License

Examples

Class with an ILog Constructor Parameter

public class InjectableClass {
    private readonly ILog _logger;
    
    public InjectableClass(ILog logger){
        _logger = logger;
    }
}

Class with an ILog Property

public class InjectableClass {
    public ILog Logger { get; set; }
}

Simple Module Registration

var builder = new ContainerBuilder();
builder.RegisterModule<Log4NetModule>();

Custom Module Registration

var builder = new ContainerBuilder();
var loggingModule =
    new Log4NetModule()
    {
        ConfigFileName = "logger.config",
        ShouldWatchConfiguration = true
    };
builder.RegisterModule(loggingModule);

Mapping Types and Namespaces to Loggers

var builder = new ContainerBuilder();
var loggingModule = new Log4NetModule();
loggingModule.MapTypeToLoggerName(typeof(InjectableClass), "Logger1");
loggingModule.MapNamespaceToLoggerName("Autofac.log4net", "Logger2");
builder.RegisterModule(loggingModule);

autofac.log4net's People

Contributors

123123123123123123123 avatar eran-gil avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.