LogAdapter.NLog

LogAdapter.NLog library.


Keywords
License
MIT
Install
Install-Package LogAdapter.NLog -Version 1.0.1

Documentation

LogAdapter Build Status Build status

  • LogAdapter NuGet
  • LogAdapter.NLog NuGet
  • LogAdapter.Log4Net NuGet
  • LogAdapter.Logary NuGet

Adapter for library logging (for current and future logging frameworks). LogAdapter is not a logging framework. It is intended to be used instead of a logger in order to let the consumer of a library choose how to log things.

Goal

Avoid taking on a dependency on a logging library for a library. The intent is that in your application code you can take a dependency on a specific version of a logging framework, and create a LogAdapter implementation for that specific version. A library should not determine what kind of logging you choose for your application.

Installation

Copy the following code to your library:

public delegate void Logger(Exception expn = null,
                                object fields = null,
                                string fatal = null,
                                string error = null,
                                string warn = null,
                                string debug = null,
                                string info = null);

Then when consuming the library create your adapter for this method.

Usage

    public class MyClass
    {
        private readonly Logger _logger;
        public MyClass(Logger logger)
        {
            _logger = logger;
        }

        public SomeValue Get(int id) 
        {
            try
            {
                // do stuff ...
                return new SomeValue{ SomeThing=something };
            }
            catch (Exception ex)
            {
                _logger(ex, error: "fail");
                return SomeValue.Failure();
            }
        }
    }