Giter Club home page Giter Club logo

rebus.nlog's Introduction

Rebus.NLog

install from nuget

Provides an NLog logger integration for Rebus.

How to use it

When you configure Rebus by calling the ordinary configuration spell

Configure.With(yourFavoriteContainerAdapter)
	.Transport(t => t.UseYourFavoriteTransport("with-this-queue"))
	.Start();

Rebus will default to log things to the console, using colors to differentiate between the four different log levels used.

You can make Rebus use NLog like this:

Configure.With(yourFavoriteContainerAdapter)
	.Logging(l => l.NLog())
	.Transport(t => t.UseYourFavoriteTransport("with-this-queue"))
	.Start();

and that's basically it :)

Please check out the NLog site for details on how to configure NLog.


rebus.nlog's People

Contributors

mookid8000 avatar snakefoot avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

kendallb

rebus.nlog's Issues

Documentation

Why isn't there any documentation provided for this extension?

NLog CallSite requires typeof(NLogLogger)

Restore NLog Callsite like this:

using System;
using NLog;
using Rebus.Logging;

namespace Rebus.NLog;

class NLogLoggerFactory : AbstractRebusLoggerFactory
{
    protected override ILog GetLogger(Type type)
    {
        if (type == null) throw new ArgumentNullException(nameof(type));
        return new NLogLogger(LogManager.GetLogger(type.FullName));
    }

    class NLogLogger : ILog
    {
        readonly Logger _logger;

        public NLogLogger(Logger logger) => _logger = logger ?? throw new ArgumentNullException(nameof(logger));

        public void Debug(string message, params object[] objs)
        {
            if (!_logger.IsDebugEnabled) return;
            Log(LogLevel.Debug, null, message, objs);
        }

        public void Info(string message, params object[] objs)
        {
            if (!_logger.IsInfoEnabled) return;
            Log(LogLevel.Info, null, message, objs);
        }

        public void Warn(string message, params object[] objs)
        {
            if (!_logger.IsWarnEnabled) return;
            Log(LogLevel.Warn, null, message, objs);
        }

        public void Warn(Exception exception, string message, params object[] objs)
        {
            if (!_logger.IsWarnEnabled) return;
            Log(LogLevel.Warn, exception, message, objs);
        }

        public void Error(string message, params object[] objs)
        {
            if (!_logger.IsErrorEnabled) return;
            Log(LogLevel.Error, null, message, objs);
        }

        public void Error(Exception exception, string message, params object[] objs)
        {
            if (!_logger.IsErrorEnabled) return;
            Log(LogLevel.Error, exception, message, objs);
        }

        private void Log(LogLevel logLevel, Exception exception, string message, object[] parameters)
        {
            // Allow NLog callsite to work, by providing typeof(NLogLogger)
            _logger.Log(typeof(NLogLogger), LogEventInfo.Create(logLevel, _logger.Name, exception, null, message, parameters));
        }
    }
}

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.