-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CachedLayoutRenderWrapper missing AmbientProperty attribute #1107
Comments
Thanks for this report. I'm not sure if
|
Config parameter is parsed but it seems that it is never assigned to the CachedLayoutRendererWrappers property. My config entry for the file target:
In NLog/src/NLog/Layouts/LayoutParser.cs Line 335 in 67ce7be
When AmbientProperty is missing the setter is just called once to assign default value in the constructor. When I add the AmbientProperty , ClearCache value is correctly set. It is set one time to the default value defined in constructor and second time to the value from config file. Note: I also changed the fileName attribute of my FileTarget in a way that it corresponds to the test you have linked.
This resulted in assigning the ClearCache value correctly. But now its cutting of year and month from the log file name and uses them to extend the path. So I get C:\somePath\year\month\trimmedDate_Log.txt instead of C:\somePath\Date_Log.txt |
Found my fault: Changed fileName="C:\somePath{cached:${date}:cached=True:clearCache=None:format=yyyy-MM-dd_HH-mm-ss}_Log.txt" to fileName="C:\somePath${cached:${date:format=yyyy-MM-dd_HH-mm-ss}:cached=True:clearCache=None}_Log.txt" I think https://github.com/NLog/NLog/wiki/Cached-Layout-Renderer should mention this in some way. |
Thanks for the examples! Which NLog version is this? Did you checked the internal log for the first case? |
@Quergo can you give us some more info? |
I'm on vacation until 14th of Jan. Will provide more info when I am back. |
Thanks for the feedback and have a nice vacation! |
So, I have new info: All I did was following documentation under https://github.com/nlog/nlog/wiki/Cached-Layout-Renderer . The logfile snippets I posted cover just the initialization part of NLog. My original FileTarget was: <target name="default_logfile"
xsi:type="File"
fileName="C:\Log\${date:cached=True:format=yyyy-MM-dd_HH-mm-ss}_Log.txt"
layout="|${level:uppercase=true} @ ${logger:shortName=true}|:${date:format=yyyy-MM-dd HH\:mm\:ss} ${message} ${exception:format=tostring, stacktrace:separator=*}" /> This works correctly until I reconfigure LogConfiguration at runtime which triggers an update of the cached value. Internal Logfile:
To avoid cache reset I tried to use FileTarget with clearCache=None : <target name="default_logfile"
xsi:type="File"
fileName="C:\Log\${date:cached=True:clearCache=None:format=yyyy-MM-dd_HH-mm-ss}_Log.txt"
layout="|${level:uppercase=true} @ ${logger:shortName=true}|:${date:format=yyyy-MM-dd HH\:mm\:ss} ${message} ${exception:format=tostring, stacktrace:separator=*}" /> Unfortunately this does not work as it still triggers an update of the cached value. In the following logfile section on can see that the clearCache value is never set when NLog initializes and will stay on it's default value (OnInit,OnClose). Internal Logfile:
My solution was to add Internal Logfile:
In a previous post I also mentioned an other solution which does not use AmbientProperty to solve this issue. fileName="C:\somePath\${cached:${date:format=yyyy-MM-dd_HH-mm-ss}:cached=True:clearCache=None}_Log.txt" But this is not like it is stated in the docs. Docs explicitly name the use of AmbientProperty which seems not to be supported for clearCache parameter. |
Thanks for all the info! This is fixed in NLog 4.3 :) |
Class CachedLayoutRendererWrapper has a missing AmbientProperty attribute for property 'ClearCache'. In consequence the value of parameter 'ClearCache' in a config file is never applied to this property because parameter is not parsed.
The text was updated successfully, but these errors were encountered: