Giter Club home page Giter Club logo

Comments (12)

snakefoot avatar snakefoot commented on June 22, 2024

NLog will only auto-scan for possible locations that can contain an NLog Configuration (Ex. app.config), when creating NLog Logger and no NLog Configuration has been loaded already.

Try manually loading/assigning the NLog Configuration before the first NLog Logger is created (Ex. before calling LogManager.GetCurrentClassLogger() or LogManager.GetLogger()).

Maybe at application-startup before anything has happened, then just assign empty configuration:

LogManager.Configuration = new LoggingConfiguration();

from nlog.

Ducatel avatar Ducatel commented on June 22, 2024

In fact the code posted previsouly is already called at the beginning.
I tried to add LogManager.Configuration = new LoggingConfiguration(); right after the assembly load but, I face the exact same Exception, just sooner.

from nlog.

snakefoot avatar snakefoot commented on June 22, 2024

from nlog.

Ducatel avatar Ducatel commented on June 22, 2024

Sure here the main thread where the init of NLog is done

image

And here the thread which throw the exception (only Ms code here)
image

from nlog.

snakefoot avatar snakefoot commented on June 22, 2024

Not sure what the NLog-project can do about other threads throwing exceptions, when accessing app.config.

Again NLog will not probe app.config if you assign NLog LogManager.Configuration upfront, before creating the first NLog Logger.

Avoid using the LogManager.Configuration-property-getter. This means not doing it like this:

NLog.LogManger.Configuration ??= new LoggingConfiguration();

And not doing it like this:

NLog.LogManger.Configuration = NLog.LogManger.Configuration ?? new LoggingConfiguration();

from nlog.

Ducatel avatar Ducatel commented on June 22, 2024

I add the creation of the configuration on the very first line of my assembly entrypoint

image

And it seems to crash here

image

I downloaded the source and I will try to debug that

from nlog.

snakefoot avatar snakefoot commented on June 22, 2024

Looking forward to hear if you have any findings. Sounds like a bug if LogFactory-constructor is throwing exceptions, before having loaded the NLog-configuration.

from nlog.

Ducatel avatar Ducatel commented on June 22, 2024

Seems to come from static object initialization which occur on Assembly.load() done on my C++ cli side.
It's very difficult to debug because seems to have kind of timing issue. When I put breakpoint into static constructor of LogFactory, the exception isn't throw.

As I try to load the assembly which use NLog from a custom AppDomain where I set a different app.config, maybe the config isn't properly initialized when NLog try to read into

from nlog.

snakefoot avatar snakefoot commented on June 22, 2024

Yes not a big fan of static constructors, as type-load-exceptions are really nasty. But sadly enough this is currently the way that NLog hookup to the AppDomain-event-handlers to ensure automatic flush on application-exit.

from nlog.

snakefoot avatar snakefoot commented on June 22, 2024

Closing due to inactivity. Hopefully with NLog v6, then auto-loading and static-constructors will be removed.

from nlog.

Ducatel avatar Ducatel commented on June 22, 2024

Yes, I keep using my old v4 version with my own workarround until you release the V6. Do you have any ideas about when you when to release it ?

from nlog.

snakefoot avatar snakefoot commented on June 22, 2024

NLog is a spare time project, and with the current speed, then I guess NLog v6 RTM will be in year. But maybe a NLog v6 Preview will arrive in 3-6 months.

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.