Log4net - How Yo Set Logging Directory at Runtime?

Hi

Log4net is configured in Config/log4net.config.

I need to set the path for where the log file should be placed dynamically at runtime.

I have adding the following code to global.asax (and OnApplicationStarting)

    log4net.GlobalContext.Properties["path"] = "testlog";
    log4net.Config.XmlConfigurator.Configure();

plus changed the configuration to

 <file type="log4net.Util.PatternString"  value="c:\Logs\%property{path}\UmbracoTraceLog.log" />

in log4net.config

It starts with creating a directory c:\Logs\(null)\UmbracoTraceLog.log - and begins logging - and after a short while it creates the wanted directory - c:\Logs\testlog\UmbracoTraceLog.log - and continues the logging in this directory.

I seem not to be able to hook in before the logging starts. Anybody having a solution or idea about how I should do it - so I do not get the (null) directory first.


This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/84827-log4net-how-yo-set-logging-directory-at-runtime