log4netcastle-windsorcastle

How to use ExtendedLog4netLogger.cs to set logfile path for appender at runtime?


I am trying to figure out how to use the ExtendedLog4NetLogger.cs to change the log file path dynamically at runtime or using the LoggingFacility?

This should be something similar to using log4net directly like this:

log4net.GlobalContext.Properties["LogName"] = logName; 

How would I access the ExtendedLogger if I register log4net integration like this:

container.AddFacility<LoggingFacility>(f => f.UseLog4Net());

Update: I use the following code to register the Extended Logger

container.AddFacility<LoggingFacility>(LoggerImplementation.ExtendedLog4net).WithConfig(configFile).ToLog(Lo‌gger)); 

I get no runtime exceptions and the logger is not a null instance but I don't see the log file created at all using the global properties, I also set the config value to this for the appender:

<file type="log4net.Util.PatternString" value="%property{LogName}" />

If I just set the file property in the config file to full path it does work. I am wondering if it is not working because configuration is done before setting the global variable.


Solution

  • extendedlogger.GlobalProperties["logName"] = logName;
    

    To enable extended logger you need to do:

    container.AddFacility<LoggingFacility>(f => f.LogUsing(LoggerImplementation.ExtendedLog4net));