Code Monkey home page Code Monkey logo

log4net's People

Contributors

dependabot[bot] avatar eniks avatar stop-cran avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

log4net's Issues

Injected logger has an unrelated name

There is an issue, when resolving a graph of objects with injecting ILog in several places. For example see following code:

class A
{
    public A(B b, ILog logger)
    {
        // Injected with logger.Logger.Name is "ConsoleApp1.B" too.
    }
}

class B
{
    public B(ILog logger)
    {
        // Injected with logger.Logger.Name is "ConsoleApp1.B".
    }
}

Resolution code:

new UnityContainer()
    .AddNewExtension<Log4NetExtension>()
    .Resolve<A>();

Is it done intentionally? I'd expect to inject loggers with corresponding names in both case - A and B.

Is there a way to resolve ILog?

So I have a class that I can't pass any parameters in its constructor so instead of the usual

public class test
{
    private ILog logger;
    public test (ILog logger)
    {
        this.logger =logger;
    }
}

I'm trying to achieve something like this

public class test
{
    private ILog logger;

    public test()
    {
        logger = unityContainer.Resolve<ILog>(); //
    }
}

But trying it out, unity failed to resolve ILog so is there a way to solve this?

Problem resolving Ilog in a windows service

Hi, im using unity to resolve some dependencies in my windows service.
The win service starts 1 quartz job (https://github.com/quartznet/quartznet).
To resolve the job dependencies im using this extension https://github.com/hbiarge/Quartz.Unity

For some reason, the ilog dependency in the job gets resolved using the wrong logger. Instead of giving me the logger for SendByEmailJob it gives me the one used in the main service

public class SendByEmailJob : IJob
{
    private readonly ILog _logger;
    private readonly IDistributionLogRepository _distRepo;

    public SendByEmailJob(ILog log, IDistributionLogRepository distRepo)
    {
        _logger = log;
        _distRepo = distRepo;
    }

    public async Task Execute(IJobExecutionContext context)
    {
        _logger.Info("Starting job");
        var emailDist = await _distRepo.GetAll(DeliveryType.Email, DistributionStatusType.Ready);
        var dist = await _distRepo.Get(100);
        foreach (var item in emailDist)
        {
            System.Diagnostics.Debug.WriteLine($"DistributionId = {item.Id}");
        }
        _logger.Info("Job completed");
    }
}

So checking the Log4NetExtension class, i notice that changing the following method:

    public ResolveDelegate<BuilderContext> GetResolver(ref BuilderContext context)
    {
        Type declaringType = context.DeclaringType;

        return (ref BuilderContext c) => LogManager.GetLogger(declaringType);
    }

To this:

    public ResolveDelegate<BuilderContext> GetResolver(ref BuilderContext context)
    {
        return (ref BuilderContext c) => {
            return LogManager.GetLogger(c.DeclaringType);
        };
    }

Solves the problem and the loggers gets correctly resolved

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.