Comments (11)
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.
Hi! Thanks for opening your first issue here! Please make sure to follow the issue template - so we could help you better!
from nlog.
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.
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.
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.
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.
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.
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.
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.
Happy that you made it work :)
from nlog.
Issue resolved
from nlog.
Related Issues (20)
- How to avoid loading LoggingConfiguration from app.config HOT 12
- LogFactory should only know ITargetWithFilterChain
- Can't remove [INFO] [Microsoft.EntityFrameworkCore.Database.Command] Executed DbCommand from console logs HOT 3
- 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
- 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
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.