I am trying to use Simple Injector ( + integration MVC) v 2.5.2. for an MVC 4 Application and I need to track/log performance (execution) as well(by log4net module). Current implementation (during runtime) creates log4net file in specified path but did not write any line of text into it (when I debug it everything went with no error to the end of _logger.Info("message") ).
Does anyone try to use Simple Injector DI for log4net?
The way how I've registered log4net module is:
public static class LoggingModule
{
public static void RegisterServices(Container container)
{
string log4NetConfigFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4net.config");
log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(log4NetConfigFile));
var logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
container.RegisterSingle(logger);
}
}
And in Global.asax
LoggingModule.RegisterServices(container);
Log4net configuration file looks like so (I dont think there is any problem):
<log4net>
<appender name="PerformanceLogFile" type="log4net.Appender.RollingFileAppender" >
<param name="File" value="..\Performance\PricingManager" />
<param name="AppendToFile" value="true" />
<param name="RollingStyle" value="Date" />
<param name="DatePattern" value="_yyyy-MM-dd.lo\g" />
<param name="MaxSizeRollBackups" value="10" />
<param name="StaticLogFileName" value="false" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%m%n"/>
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<param name="LevelMin" value="INFO" />
<param name="LevelMax" value="FATAL" />
</filter>
</appender>
<logger name="SoftTech.PricingEngine.PricingService.PerformanceStatisticLoggerWithAPI">
<level value="ALL" />
<appender-ref ref="PerformanceLogFile" />
</logger>
</log4net>
And to turn on/off logging I've been using:
private static void RegisterIPerformanceStatisticLogger(Container container)
{
if (ShouldLogPerformance())
{
container.Register<IPerformanceStatisticLogger, PerformanceStatisticLogger>(WebLifestyle);
}
else
{
// do nothing
container.Register<IPerformanceStatisticLogger, DisabledPerformanceStatisticLogger>(WebLifestyle);
}
}
And PerformanceStatisticLogger or DisablePerformanceStatisticLogger sets
IsLoggingEnabled = true; // | false
IsAPITraceEnabled = false; // | true
What I am doing wrong? Seems to me the problem of the way of injection. Thanks for any advice