{"action":"created","issue":{"url":"https://api.github.com/repos/net-commons/common-logging/issues/81","labels_url":"https://api.github.com/repos/net-commons/common-logging/issues/81/labels{/name}","comments_url":"https://api.github.com/repos/net-commons/common-logging/issues/81/comments","events_url":"https://api.github.com/repos/net-commons/common-logging/issues/81/events","html_url":"https://github.com/net-commons/common-logging/issues/81","id":57935848,"number":81,"title":"Setting Global (Variables) Context before logger creation","user":{"login":"thomasjoscht","id":8656696,"avatar_url":"https://avatars.githubusercontent.com/u/8656696?v=3","gravatar_id":"","url":"https://api.github.com/users/thomasjoscht","html_url":"https://github.com/thomasjoscht","followers_url":"https://api.github.com/users/thomasjoscht/followers","following_url":"https://api.github.com/users/thomasjoscht/following{/other_user}","gists_url":"https://api.github.com/users/thomasjoscht/gists{/gist_id}","starred_url":"https://api.github.com/users/thomasjoscht/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thomasjoscht/subscriptions","organizations_url":"https://api.github.com/users/thomasjoscht/orgs","repos_url":"https://api.github.com/users/thomasjoscht/repos","events_url":"https://api.github.com/users/thomasjoscht/events{/privacy}","received_events_url":"https://api.github.com/users/thomasjoscht/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/net-commons/common-logging/labels/bug","name":"bug","color":"e11d21"},{"url":"https://api.github.com/repos/net-commons/common-logging/labels/question","name":"question","color":"5319e7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-02-17T15:14:18Z","updated_at":"2015-02-20T13:14:53Z","closed_at":null,"body":"Hey, trying to use log4net1213 with CL 3.0 and feature GlobalVariablesContext does not work in my scenario. For my log4net configuration in app.config I'm using %property{} for changing log file directory dynamically in my bootstrapper. Here part of my app.config:\r\n```\r\n<log4net>\r\n<appender name=\"FileAppender\" type=\"log4net.Appender.RollingFileAppender\">\r\n<file type=\"log4net.Util.PatternString\" value=\"%property{LogsDirectory}\\\\Log_\" />\r\n</appender>\r\n</log4net>\r\n```\r\nIn combination with log4net specific code all works fine:\r\n```\r\nlog4net.GlobalContext.Properties[\"LogsDirectory\"] = \"C:\\\\Logs\";\r\nvar logger = Common.Logging.LogManager.GetLogger(\"MyLogger\");\r\n```\r\nBut using new GlobalVariablesContext feature like following code will not work:\r\n```\r\nvar logger = Common.Logging.LogManager.GetLogger(\"MyLogger\");\r\nlogger.GlobalVariablesContext.Set(\"LogsDirectory\",\"C:\\\\Logs\");\r\n```\r\nThis happens propably because of setting global context after logger creation. But how can GlobalContext changed before logger creation with CL 3.0?"},"comment":{"url":"https://api.github.com/repos/net-commons/common-logging/issues/comments/75235945","html_url":"https://github.com/net-commons/common-logging/issues/81#issuecomment-75235945","issue_url":"https://api.github.com/repos/net-commons/common-logging/issues/81","id":75235945,"user":{"login":"meixger","id":600424,"avatar_url":"https://avatars.githubusercontent.com/u/600424?v=3","gravatar_id":"","url":"https://api.github.com/users/meixger","html_url":"https://github.com/meixger","followers_url":"https://api.github.com/users/meixger/followers","following_url":"https://api.github.com/users/meixger/following{/other_user}","gists_url":"https://api.github.com/users/meixger/gists{/gist_id}","starred_url":"https://api.github.com/users/meixger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meixger/subscriptions","organizations_url":"https://api.github.com/users/meixger/orgs","repos_url":"https://api.github.com/users/meixger/repos","events_url":"https://api.github.com/users/meixger/events{/privacy}","received_events_url":"https://api.github.com/users/meixger/received_events","type":"User","site_admin":false},"created_at":"2015-02-20T13:14:53Z","updated_at":"2015-02-20T13:14:53Z","body":"TBH i never used properties for log4net logfile configuration.\r\n\r\nIf you want to use a (global context) property in the log4net configuration you must set it **prior to the log4net configuration**. \r\n\r\nCommon.Logging configures log4net on the first call to Common.Logging.LogManager.GetLogger().\r\n\r\nTo access the GlobalVariablesContext we now need to call GetLogger() for an instance of an ILog. This triggers log4net configuration and because we haven't yet set the property it will be read as ´(null)´\r\n\r\nOne (dirty) way i see is re-do log4net configuration after setting GlobalVariablesContext by calling Reset:\r\n \r\n    var dummy = Common.Logging.LogManager.GetLogger(\"dummy\");\r\n    \r\n    // Reset sets ILoggingFactoryAppender to null so log4net needs to be re-configured\r\n    Common.Logging.LogManager.Reset(); \r\n    \r\n    dummy.GlobalVariablesContext.Set(\"LogsDirectory\", \"C:\\\\Logs\");\r\n\r\n    // Access to LogManager.GetLogger() triggers log4net initialization because the ILoggingFactoryAppender was set to NULL by LogManager.Reset().\r\n    var logger = Common.Logging.LogManager.GetLogger<MyLogger>();"}}