Giter Site home page Giter Site logo

fluent-log4net's Introduction

Fluent Log4Net

An alternative to XML-based log4net configuration, allowing logging to be configured using a strongly-typed fluent interface.

The goal of the project is to fully support all built-in appenders and other log4net configuration settings, and make the intention of the various settings less opaque and easier to read at a glance.

Usage

All configuration begins with the root Log4Net class and its Configure() method. The simplest possible configuration with a single console appender would be:

Log4Net.Configure()
    .Logging.Default(log => log.To.Console())
    .ApplyConfiguration();

More advanced scenarios including repository settings and custom renderers, as well as individual logger configurations can also be done. Note that most of the specific appender configurations haven't been written yet, but they are coming.

Log4Net.Configure()
    .Global.Threshold(Level.Debug)

    .Logging.Default(log => log
        .To.Console(c => c.Targeting.ConsoleOut))

    .Logging.For<MyClass>(log => log
        .At(Level.Warn)
        .To.File( ... )
        .To.Database( ... )
        .To.ColoredConsole( ... )

    .Logging.For<MyOtherClass>(log => log
        .At(Level.Error)
        .To.EventLog( ... )

    .Render.Type<Int32>().Using<Int32Renderer>()
    .Render.Type<Int64>().Using(typeof(Int64Renderer))
    .Render.Type(typeof(Single)).Using(typeof(SingleRenderer))
    .Render.Type(typeof(Double)).Using<DoubleRenderer>()

    .ApplyConfiguration();

In most cases, appenders are usually shared among several loggers. The above syntax creates separate appenders for each logger, which may not be desired. To share appender references, you can define them ahead of time using the Append.To definition builder.

var myConsoleAppender = Append.To.Console(c => c.Targeting.ConsoleOut);
var myFileAppender = Append.To
    .File(f => f
        .Named("myfile.log")
        .Append(true)
        .LockingMinimally());

Log4Net.Configure()
    .Logging.Default(log => log
        .At(Level.Debug)
        .To.Appender(myConsoleAppender))

    .Logging.For<MyClass>(log => log
        .At(Level.Error)
        .To.Appender(myFileAppender))

    .Logging.For<MyOtherClass(log => log
        .At(Level.Error)
        .To.Appender(myFileAppender))

    .ApplyConfiguration();    

Todo List

  • Support for all built-in log4net appenders
  • Validate config before applying
  • Common threshold, filter, layout, and error-handler interfaces for appenders

fluent-log4net's People

Contributors

awhatley 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.