Giter Club home page Giter Club logo

Comments (11)

champlin2 avatar champlin2 commented on June 27, 2024 1

Thank you - that seemed to do it! I didn't realize that I could get to the global LogFactory through LogManager and make the call that way

from nlog.

welcome avatar welcome commented on June 27, 2024

Hi! Thanks for opening your first issue here! Please make sure to follow the issue template - so we could help you better!

from nlog.

snakefoot avatar snakefoot commented on June 27, 2024

You can stille use the obsolete GetLogger()-call with NLog v5.3.2, ofcourse better to change to GetLogger<T> (Where T is the Logger-type)

Notice the GetLogger()-call was made obsolete with NLog v5.2, and so was also obsolete with NLog v5.2.8.

I cannot guess what you are doing from the NLog InternalLogger-output (that seems to have been edited). Maybe you can provide a small example-project that reproduces the issue?

from nlog.

champlin2 avatar champlin2 commented on June 27, 2024

The problem is we have to change it because our code scanning software is saying we can't use obsolete calls.

Does anything stand out that I'm doing wrong to change the variables because the same code worked with the old GetLogger call

from nlog.

snakefoot avatar snakefoot commented on June 27, 2024

I'm trying to guess what version of NLog you are upgrading from, and since you are saying that you cannot use obsolete calls, then you cannot be upgrading from NLog v5.2.8

from nlog.

champlin2 avatar champlin2 commented on June 27, 2024

We are upgrading from 5.2.8 - the code scanning requirement is new so that is why it is complaining now and we have to change

from nlog.

snakefoot avatar snakefoot commented on June 27, 2024

You said the issue came from upgrading from NLog v5.2.8 to NLog v5.3.2. But I guess the logging also fails without upgrading NLog?

So the problem comes from changing to other GetLogger-call ?

You are saying that you changed from this obsolete-method:

var logger = (ILoggingService)LogManager.GetLogger(logName, typeof(LoggingService));

To this code:

var logger = (ILoggingService)new LogFactory().GetLogger(logName);

Any reason why you changed to isolated new LogFactory() instead of continue using the global LogManager ?

I think you should try this instead:

var logger = (ILoggingService)LogManager.LogFactory.GetLogger<LoggingService>(logName);

from nlog.

champlin2 avatar champlin2 commented on June 27, 2024

Yes, that is the code I changed. I used 'new LogFactory()' because I want to cast the Logger that is returned to our ILoggingService interface (which is what the LoggingService class inherits from) and when I try the code above:

var logger = (ILoggingService)new LogFactory().GetLogger(logName);

it appears to work but then in the unit tests when we make sure its an instance of ILoggingService we get a failure (which does work with the new LogFactory.GetLogger(name) call -- since LogManager.GetLogger is not a generic method there is no way to pass in LoggingService to it):

    [Test]
    public void GetLoggingService_ReturnLogger()
    {
        var actual = LoggingService.GetLoggingService("test_log");
        Assert.IsInstanceOf(typeof(ILoggingService), actual);
    }

System.InvalidCastException : Unable to cast object of type 'NLog.Logger' to type 'xxxxx.ILoggingService'.
at xxxxxxTest() in xxxxxxxTests.cs:line 21

from nlog.

snakefoot avatar snakefoot commented on June 27, 2024

I think you should try this instead:

var logger = (ILoggingService)LogManager.LogFactory.GetLogger<LoggingService>(logName);

As recommended by the obsolete-statement:

[Obsolete("Replaced by LogFactory.GetLogger<T>(). Marked obsolete on NLog 5.2")]
public static Logger GetLogger(string name, Type loggerType)

from nlog.

snakefoot avatar snakefoot commented on June 27, 2024

Happy that you made it work :)

from nlog.

champlin2 avatar champlin2 commented on June 27, 2024

Issue resolved

from nlog.

Related Issues (20)

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.