Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Peter 24 posts 102 karma points
    Mar 27, 2017 @ 05:37
    Peter
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft