We have projects in VB and C# and they all have logging. Right now the implementation of a logger factory is causing memory leaks during load test. Looks like someone tried to hack the old code to support nlog and it creates counless instances of the log factory which is creating a lot of arrays and event handler leaks. I wanted to know what is the right approach to have a class that can be referenced in other projects to enable logging. Can we do something like
public interface ILogger{
void Error(string message);
void Debug(string message);
}
public NlogWrapper:ILogger{
private readonly NLog.Logger _logger;
public NLogLogger(string name)
{
_logger = NLog.LogManager.GetLogger(name);
}
Then in my other library projects I create logger insance such as
Private logger As ILogger = New NlogWrapper("Admin_" + DateTime.Now.ToString("yyyyMMdd"))
- I got confused with Nlog.LogFactory, Microsoft.Extensions.Logging and so on.
- Or am I over complicating it and just go ahead and call 'NLog.LogManager.GetLogger' in all of my projects? The only problem is see is that there might be other clients that consume the logging.dll
- Microsoft.Extensions.Logging looks like a clean approach but I am not sure where we will the framework that I will be using nlog and to load nlog configuration in a .net framework application without DI