Comments (12)
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.
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.
from nlog.
Sure here the main thread where the init of NLog is done
And here the thread which throw the exception (only Ms code here)
from nlog.
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.
I add the creation of the configuration on the very first line of my assembly entrypoint
And it seems to crash here
I downloaded the source and I will try to debug that
from nlog.
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.
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.
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.
Closing due to inactivity. Hopefully with NLog v6, then auto-loading and static-constructors will be removed.
from nlog.
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.
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)
- No logging output when using LogManager.GetCurrentClassLogger() HOT 4
- File log are deleted when MaxArchiveFiles is less than total number of multiple targets HOT 3
- Set license expression on packages HOT 3
- Add additional TFM to reduce dependencies HOT 7
- Deprecate additional Nuget Packages HOT 4
- Allow for the removal of the inherent callsite information in fluent logs (?) HOT 4
- Unused target detected. Add a rule for this target to the configuration. But a rule does exist in the configuration. HOT 4
- NLog.Database version 5.2.8 with net8 error HOT 8
- Visual Studio 2022 build LoggerWrapper project failed with "Can't find .NETFramework,Version=v4.0" error message HOT 7
- NetworkTarget with GELF fails when sending UDP message larger than MaxMessageSize HOT 14
- RegisterObjectTransformation not working with ${exception:format=ToString,Properties,Data} HOT 3
- Logging not working when using Azure SDK from a library project in .NET Core (Dependency Injection) HOT 3
- LogManager.GetLogger(Type) marked as obsolete, what to use instead? HOT 11
- How to get the Request Properties like RequestPath and RequestDetail in a class file, update it and add them back to the logs HOT 7
- Layout.FromMethod that supports typed Layout
- [Question] Is there a built-in byte[] to hex formatter? HOT 17
- NLog configuration not loading when running on Ubuntu 22.04 HOT 3
- Support params ReadOnlySpan with NetStandard2.1 and lang version 13
- Veracode scan gives Use of a Broken or Risky Cryptographic Algorithm CWE ID 327 Error for NLog HOT 3
- Please add `queueLimit` and `overflowAction` to `FileTarget`. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nlog.