New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable wrapping of an existing NLog.Logger as a Microsoft.Extensions.Logging.ILogger #455
Comments
Sounds a lot like this thread: dotnet/runtime#35995 Have you read this wiki-page: https://github.com/NLog/NLog.Extensions.Logging/wiki/NLog-properties-with-Microsoft-Extension-Logging Maybe this is what you are looking for: https://www.nuget.org/packages/XeonApps.Extensions.Logging.WithProperty/ |
Thanks for your quick response @snakefoot. This is indeed related to the referenced dotnet issue. I had been reading the article https://github.com/NLog/NLog.Extensions.Logging/wiki/NLog-properties-with-Microsoft-Extension-Logging a couple of times, but I was so focused on trying to understand why NLog did not provide a way of wrapping an The work done here looks very good: https://github.com/viktor-nikolaev/XeonApps.Extensions.Logging.WithProperty - I see that @304NotModified has contributed to it as well. Are there any plans for the NLog project to provide a similar abstraction? Would be nice to see in the framework. Thanks again for your help. |
@swlasse Since these extension methods are not really NLog-specific then it might not make sense to have them in a NLog-specific-package. Also dragging random code into the NLog-project, means that someone has to maintain and support it. Rather scarce with developer resources on the NLog-project. |
@snakefoot I totally understand your reasoning for not taking this in just out-of-the-box, which is fair :) I guess it is also a question of where you want to draw the line. I mean, why should you invest heavily in supporting extensions on top of the The reason I initially created this issue is because I am in a project where I am trying to standardize on logging. The On a final note; should I find time some day, would you be interested in accepting a PR with a solution based on https://github.com/viktor-nikolaev/XeonApps.Extensions.Logging.WithProperty or is your previous answer a "clear" no go on this? |
@swlasse Pull-requests from eager hands are always welcome. There is some dependency issue that might annoy some, as the NLog.Extension.Logging caries some other baggage like configuration-loading. Maybe it should be an isolated package just like NLog.Extension.Hosting? (All business-logic libraries that wants these extension method suddenly all have to depend on this package). Then there is issue about what namespace to put such extension-methods. |
@snakefoot Alright, that sounds good. Yeah, naming is hard! If I get the time, I will see what I can come up with. I am glad for the input you have provided on this issue, and I believe I have the information I need to move on. Thanks again. |
Type (choose one):
NLog version: 4.7.5
NLog.Extensions.Logging version: 1.6.5
NLog.Web.AspNetCore version: not used
Platform: .NET Core 3.1
Based on https://github.com/NLog/NLog/wiki/EventProperties-Layout-Renderer#logger-withproperty-or-setproperty I am creating a logger with event properties specified during logger creation:
In my code base, I am already using the
Microsoft.Extensions.Logging.ILogger<T>
abstraction, and I would like to use this NLog poweredpropertyLogger
as an instance implementing thisMEL.ILogger
interface (to keep things clean). Example:I have been looking around in the
NLog.Extensions.Logging
project to see if I could find a way to wrap an existing instance of anNLog.Logger
as anMEL.ILogger
, but I have not had any luck. The closest I get is theNLogLogger
type which is marked asinternal
and therefore cannot be instantiated "outside".Questions:
A) Is is possible to wrap an existing instance of an
NLog.Logger
as anMEL.ILogger
today? If so, how should that be done?B) If not, would it be an option for you to provide framework support for this? I am not sure if it is as simple as updating the access modifier on
NLogLogger
frominternal
topublic
? Probably not :)Thanks in advance for your help.
Best regards,
Lasse ( a 10+ years happy user of NLog :)
The text was updated successfully, but these errors were encountered: