i am in process of using Log4Net and want to refactor the logging. I added the Log4Net config to the indicator but realized that every time i called to log a message, its going to initialize log4net. is there a better way?
using System;
using log4net;
using System.IO;
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator {
private static ILog logr = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private void ConfigureLog4Net()
{
log4net.Config.XmlConfigurator.Configure(new FileInfo(Core.Globals.UserDataDir + @"bin\custom\Log4Net.config"));
log4net.Config.XmlConfigurator.Configure();
}
public void LogMessage(Object o){
ConfigureLog4Net();
logr.Info(o);
}
public void LogException(Exception e){
ConfigureLog4Net();
logr.Fatal(e);
}
}
}
using System;
using log4net;
using System.IO;
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator {
private static ILog logr = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private void ConfigureLog4Net()
{
log4net.Config.XmlConfigurator.Configure(new FileInfo(Core.Globals.UserDataDir + @"bin\custom\Log4Net.config"));
log4net.Config.XmlConfigurator.Configure();
}
public void LogMessage(Object o){
ConfigureLog4Net();
logr.Info(o);
}
public void LogException(Exception e){
ConfigureLog4Net();
logr.Fatal(e);
}
}
}