Enable wrapping of an existing NLog.Logger as a Microsoft.Extensions.Logging.ILogger
See original GitHub issueType (choose one):
- Feature request
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:
// Creates an NLog.Logger
NLog.Logger propertyLogger = LogManager.GetCurrentClassLogger(typeof(MyLogger)).WithProperty("key1", "val1");
In my code base, I am already using the Microsoft.Extensions.Logging.ILogger<T>
abstraction, and I would like to use this NLog powered propertyLogger
as an instance implementing this MEL.ILogger
interface (to keep things clean). Example:
// I am looking for something like this
Microsoft.Extensions.Logging.ILogger melLogger = NLogLogger.Wrap(propertyLogger);
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 an NLog.Logger
as an MEL.ILogger
, but I have not had any luck. The closest I get is the NLogLogger
type which is marked as internal
and therefore cannot be instantiated “outside”.
Questions:
A) Is is possible to wrap an existing instance of an NLog.Logger
as an MEL.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
from internal
to public
? Probably not 😃
Thanks in advance for your help.
Best regards, Lasse ( a 10+ years happy user of NLog 😃
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Sounds a lot like this thread: https://github.com/dotnet/runtime/issues/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/
@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.