{"action":"created","issue":{"url":"https://api.github.com/repos/NLog/NLog/issues/1381","repository_url":"https://api.github.com/repos/NLog/NLog","labels_url":"https://api.github.com/repos/NLog/NLog/issues/1381/labels{/name}","comments_url":"https://api.github.com/repos/NLog/NLog/issues/1381/comments","events_url":"https://api.github.com/repos/NLog/NLog/issues/1381/events","html_url":"https://github.com/NLog/NLog/issues/1381","id":149103363,"number":1381,"title":"StackOverflowException when File target's fileName uses ${var:mydir} instead of ${mydir}","user":{"login":"AndreGleichner","id":8420678,"avatar_url":"https://avatars.githubusercontent.com/u/8420678?v=3","gravatar_id":"","url":"https://api.github.com/users/AndreGleichner","html_url":"https://github.com/AndreGleichner","followers_url":"https://api.github.com/users/AndreGleichner/followers","following_url":"https://api.github.com/users/AndreGleichner/following{/other_user}","gists_url":"https://api.github.com/users/AndreGleichner/gists{/gist_id}","starred_url":"https://api.github.com/users/AndreGleichner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndreGleichner/subscriptions","organizations_url":"https://api.github.com/users/AndreGleichner/orgs","repos_url":"https://api.github.com/users/AndreGleichner/repos","events_url":"https://api.github.com/users/AndreGleichner/events{/privacy}","received_events_url":"https://api.github.com/users/AndreGleichner/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/NLog/NLog/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/NLog/NLog/labels/must%20have","name":"must have","color":"000000"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/NLog/NLog/milestones/19","html_url":"https://github.com/NLog/NLog/milestones/4.3.1","labels_url":"https://api.github.com/repos/NLog/NLog/milestones/19/labels","id":1660732,"number":19,"title":"4.3.1","description":"","creator":{"login":"304NotModified","id":5808377,"avatar_url":"https://avatars.githubusercontent.com/u/5808377?v=3","gravatar_id":"","url":"https://api.github.com/users/304NotModified","html_url":"https://github.com/304NotModified","followers_url":"https://api.github.com/users/304NotModified/followers","following_url":"https://api.github.com/users/304NotModified/following{/other_user}","gists_url":"https://api.github.com/users/304NotModified/gists{/gist_id}","starred_url":"https://api.github.com/users/304NotModified/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/304NotModified/subscriptions","organizations_url":"https://api.github.com/users/304NotModified/orgs","repos_url":"https://api.github.com/users/304NotModified/repos","events_url":"https://api.github.com/users/304NotModified/events{/privacy}","received_events_url":"https://api.github.com/users/304NotModified/received_events","type":"User","site_admin":false},"open_issues":2,"closed_issues":0,"state":"open","created_at":"2016-03-22T20:13:20Z","updated_at":"2016-04-18T21:51:33Z","due_on":null,"closed_at":null},"comments":8,"created_at":"2016-04-18T09:56:30Z","updated_at":"2016-04-19T08:28:34Z","closed_at":null,"body":"I'm using a variable \"mydir\" to hold the actual path where a file target should create its log file.\r\nWhen referencing it via ${var:mydir} it throws a StackOverflowException.\r\nWhen using the (no longer recomended?) `${mydir}` it works.\r\nHave used NLog 4.2.3 before which works fine with `${var:mydir}`.\r\nMy actual NLog.config is much more complicated, so that the use of a variable makes sense...\r\n\r\n**Type**: Bug\r\n**NLog version**: 4.3.0\r\n**Platform**: .Net 4.0 on Win10\r\n\r\n**Current NLog config** (xml or C#, if relevant)\r\n\r\n```xml\r\n<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n<nlog xmlns=\"http://www.nlog-project.org/schemas/NLog.xsd\"\r\n      xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n      xsi:schemaLocation=\"http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd\"\r\n      autoReload=\"true\"\r\n      throwExceptions=\"false\"\r\n      internalLogLevel=\"Trace\" internalLogFile=\"c:\\temp\\nlog-internal.log\" >\r\n    \r\n    <variable name=\"mydir\" value=\"c:\\temp\\HelloNlog\"/>\r\n    <targets>\r\n        <target name=\"fileAll\" xsi:type=\"File\" fileName=\"${var:mydir}\\Test.log\" />\r\n    </targets>\r\n    <rules>\r\n        <logger name=\"*\" writeTo=\"fileAll\" />\r\n    </rules>\r\n</nlog>\r\n\r\n```\r\n\r\nIn case of a BUG:\r\n\r\n- What is the current result? StackOverflowException\r\n- What is the expected result? \r\n- Did you checked the [Internal log](https://github.com/NLog/NLog/wiki/Internal-Logging)?\r\n Yes, but gives no clear indication of what went wrong.\r\n- Please post full exception details (message, stacktrace, inner exceptions)\r\n See below.\r\n- Are there any work arrounds? yes, use ${mydir} instead of ${var:mydir}\r\n- Is there a version in which it did worked? 4.2.3\r\n- Can you help us by writing an unit test? \r\n Don't know enough about NLog's inner workings.\r\n\r\nIt recurses endlessly invoking NLog.Targets.FileTarget.FileName.set.\r\nWhile doing a short debug session, I wasn't able to spot the root cause.\r\n\r\n**Stacktrace:**\r\n\r\n```\r\n \t...\r\n \tNLog.dll!**NLog.Targets.FileTarget.FileName.set**(NLog.Layouts.Layout value) Line 240\r\n \tNLog.dll!NLog.Internal.PropertyHelper.SetPropertyFromString(object obj, string propertyName, string value, NLog.Config.ConfigurationItemFactory configurationItemFactory) Line 93\r\n \tNLog.dll!NLog.Config.XmlLoggingConfiguration.ConfigureObjectFromAttributes(object targetObject, NLog.Config.NLogXmlElement element, bool ignoreType) Line 1109\r\n \tNLog.dll!NLog.Config.XmlLoggingConfiguration.ParseTargetElement(NLog.Targets.Target target, NLog.Config.NLogXmlElement targetElement) Line 802\r\n \tNLog.dll!NLog.Config.XmlLoggingConfiguration.ParseTargetsElement(NLog.Config.NLogXmlElement targetsElement) Line 778\r\n \tNLog.dll!NLog.Config.XmlLoggingConfiguration.ParseNLogElement(NLog.Config.NLogXmlElement nlogElement, string filePath, bool autoReloadDefault) Line 560\r\n \tNLog.dll!NLog.Config.XmlLoggingConfiguration.ParseTopLevel(NLog.Config.NLogXmlElement content, string filePath, bool autoReloadDefault) Line 478\r\n \tNLog.dll!NLog.Config.XmlLoggingConfiguration.Initialize(System.Xml.XmlReader reader, string fileName, bool ignoreErrors) Line 383\r\n \tNLog.dll!NLog.Config.XmlLoggingConfiguration.XmlLoggingConfiguration(string fileName, bool ignoreErrors, NLog.LogFactory logFactory) Line 129\r\n \tNLog.dll!NLog.Config.XmlLoggingConfiguration.XmlLoggingConfiguration(string fileName, NLog.LogFactory logFactory) Line 105\r\n \tNLog.dll!NLog.LogFactory.LoadLoggingConfiguration(string configFile) Line 1043\r\n \tNLog.dll!NLog.LogFactory.Configuration.get() Line 186\r\n \tNLog.dll!NLog.LogManager.Configuration.get() Line 157\r\n \tNLog.dll!NLog.LayoutRenderers.VariableLayoutRenderer.Append(System.Text.StringBuilder builder, NLog.LogEventInfo logEvent) Line 73\r\n \tNLog.dll!NLog.LayoutRenderers.LayoutRenderer.Render(System.Text.StringBuilder builder, NLog.LogEventInfo logEvent) Line 161\r\n \tNLog.dll!NLog.Layouts.SimpleLayout.GetFormattedMessage(NLog.LogEventInfo logEvent) Line 281\r\n \tNLog.dll!NLog.Layouts.Layout.Render(NLog.LogEventInfo logEvent) Line 140\r\n \tNLog.dll!NLog.Targets.FileTarget.GetCleanedFileName(NLog.LogEventInfo logEvent) Line 871\r\n \tNLog.dll!NLog.Targets.FileTarget.RefreshFileArchive() Line 607\r\n \tNLog.dll!**NLog.Targets.FileTarget.FileName.set**(NLog.Layouts.Layout value) Line 240\r\n \tNLog.dll!NLog.Internal.PropertyHelper.SetPropertyFromString(object obj, string propertyName, string value, NLog.Config.ConfigurationItemFactory configurationItemFactory) Line 93\r\n \tNLog.dll!NLog.Config.XmlLoggingConfiguration.ConfigureObjectFromAttributes(object targetObject, NLog.Config.NLogXmlElement element, bool ignoreType) Line 1109\r\n \tNLog.dll!NLog.Config.XmlLoggingConfiguration.ParseTargetElement(NLog.Targets.Target target, NLog.Config.NLogXmlElement targetElement) Line 802\r\n \tNLog.dll!NLog.Config.XmlLoggingConfiguration.ParseTargetsElement(NLog.Config.NLogXmlElement targetsElement) Line 778\r\n \tNLog.dll!NLog.Config.XmlLoggingConfiguration.ParseNLogElement(NLog.Config.NLogXmlElement nlogElement, string filePath, bool autoReloadDefault) Line 560\r\n \tNLog.dll!NLog.Config.XmlLoggingConfiguration.ParseTopLevel(NLog.Config.NLogXmlElement content, string filePath, bool autoReloadDefault) Line 478\r\n \tNLog.dll!NLog.Config.XmlLoggingConfiguration.Initialize(System.Xml.XmlReader reader, string fileName, bool ignoreErrors) Line 383\r\n \tNLog.dll!NLog.Config.XmlLoggingConfiguration.XmlLoggingConfiguration(string fileName, bool ignoreErrors, NLog.LogFactory logFactory) Line 129\r\n \tNLog.dll!NLog.Config.XmlLoggingConfiguration.XmlLoggingConfiguration(string fileName, NLog.LogFactory logFactory) Line 105\r\n \tNLog.dll!NLog.LogFactory.LoadLoggingConfiguration(string configFile) Line 1043\r\n \tNLog.dll!NLog.LogFactory.Configuration.get() Line 186\r\n \tNLog.dll!NLog.LogFactory.GetLogger(NLog.LogFactory.LoggerCacheKey cacheKey) Line 989\r\n \tNLog.dll!NLog.LogFactory.GetLogger(string name) Line 446\r\n \tNLog.dll!NLog.LogManager.GetCurrentClassLogger() Line 190\r\n \tTestNlog.exe!TestNlog.Program.Program() Line 11\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/NLog/NLog/issues/comments/211793167","html_url":"https://github.com/NLog/NLog/issues/1381#issuecomment-211793167","issue_url":"https://api.github.com/repos/NLog/NLog/issues/1381","id":211793167,"user":{"login":"AndreGleichner","id":8420678,"avatar_url":"https://avatars.githubusercontent.com/u/8420678?v=3","gravatar_id":"","url":"https://api.github.com/users/AndreGleichner","html_url":"https://github.com/AndreGleichner","followers_url":"https://api.github.com/users/AndreGleichner/followers","following_url":"https://api.github.com/users/AndreGleichner/following{/other_user}","gists_url":"https://api.github.com/users/AndreGleichner/gists{/gist_id}","starred_url":"https://api.github.com/users/AndreGleichner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndreGleichner/subscriptions","organizations_url":"https://api.github.com/users/AndreGleichner/orgs","repos_url":"https://api.github.com/users/AndreGleichner/repos","events_url":"https://api.github.com/users/AndreGleichner/events{/privacy}","received_events_url":"https://api.github.com/users/AndreGleichner/received_events","type":"User","site_admin":false},"created_at":"2016-04-19T08:28:34Z","updated_at":"2016-04-19T08:28:34Z","body":"The actual StackOverflowException got fixed with 4.3.1-rc1, but now it tries creating the logfile in c:\\Test.log instead of c:\\temp\\HelloNlog\\Test.log.\r\n\r\nAgain, when not using ${var:...} it works.\r\n\r\nDidn't know that ${var:...} are performing worse, I somehow interpreted this https://github.com/NLog/NLog/wiki/Configuration-file#vars-since-nlog-41 as a recomendation towards that new syntax.\r\n"}}