I am on NLog 4.3.5.
I have a long, complicated layout string that I want to save in a <variable /> for use in four layout attributes. Unfortunately, if I refer to the variable using
layout="${layout_full}"
then NLog complains that it cannot find that layout formatter (even though it isn't a layout formatter, it's a variable); and if I refer to the variable using
layout="${var:layout_full}"
then the layout evaluates to a blank string.
In other words, this:
<variable name="layout-full" value="
${longdate} [${level}] ${logger} ${all-event-properties}${newline}
${message}
${when:when='${exception}'!='':inner=
${newline}${exception}
${newline}${stacktrace}}
" />
<target name="stdout" xsi:type="Console" error="false" layout="a${var:layout-full}b" />
shows all log entries as "ab".
I have also tried putting all four targets into a SplitGroup and applying a layout to the group, but that's apparently unsupported.
Not sure if this is the case here, but the <variable> should be outside the <target> and <targets>
Related
I'm new to NLog and I confused with layout and layout-renderers.
I saw following code\pages:
https://github.com/NLog/NLog/wiki/Configuration-API
Layout = #"${date:format=HH\:mm\:ss} ${level} ${message} ${exception}"
https://github.com/NLog/NLog/wiki/CsvLayout (xml)
https://github.com/NLog/NLog/wiki/Exception-Layout-Renderer (something like the first)
I understand first (format of log message), but what is second and third I don't understand.
Layouts are defining the layout of the rendered output, examples are a CSV, JSON, XML (NLog 4.6+) or plain layout (the default). There are currently 5 layouts in NLog (including the default): https://nlog-project.org/config/?tab=layouts
Layout renderers are rendering values, e.g. a message, an exception, the process id etc. Also called "template markers". The layout renders looking as ${something}. There are around 100 layout renderers in NLog, but there are also some 3rd party layout renderers. See https://nlog-project.org/config/?tab=layout-renderers
You can see a layout as a method to combine layout renderers. The default layout is a bit hidden, but other layouts should make it more clear. See the examples below.
Some examples:
Default layout
Layout = #"${date:format=HH\:mm\:ss} ${level} ${message} ${exception}"
This is the default layout with 4 layout renderers (date, level, message, exception)
JSON layout
A file target with a JsonLayout with the same 4 layout renderers:
<target name='jsonFile' type='File' fileName='log.json'>
<layout type='JsonLayout'>
<attribute name='time' layout='${longdate}' />
<attribute name='level' layout='${level:upperCase=true}'/>
<attribute name='message' layout='${message}' />
<attribute name='exception' layout='${exception}' />
</layout>
</target>
This will create file with e.g. { "time": "2016-10-30 13:30:55.0000", "level": "INFO", "message": "this is message", "exception": "test" }
The same for CSV, but then to create CSV files (or CSV to the database etc).
Exception layout renderer: ${exception}
(See also https://github.com/NLog/NLog/wiki/Exception-Layout-Renderer)
This is for rendering the exception, as exceptions are captured separate from the message in NLog. See also How to proper log exceptions
I am lost. I've got a Web project that comes with a config file and several parameters which need to be set differently per target environment. I have an app setting and a connection string. The DEFINE values need to be replaced.
Web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="HostUri" value="DEFINE"/>
...
</appSettings>
<connectionStrings>
<add name="DbConn" connectionString="DEFINE" providerName="System.Data.SqlClient"/>
</connectionStrings>
...
</configuration>
I've got a parameter specification which an Azure App Service Deploy task uses later during deployment. Here, I specified both values to be replaced.
parameters.xml:
<parameters>
<parameter name="HostUri" defaultValue="Replace me!">
<parameterEntry kind="XmlFile" scope="Web.config"
match="/configuration/appSettings/add[#key='HostUri']/#value" />
</parameter>
<parameter name="DbConn" defaultValue="Replace me!">
<parameterEntry kind="XmlFile" scope="Web.config"
match="/configuration/connectionStrings/add[#name='DbConn']/#connectionString" />
</parameter>
</parameters>
While the app setting HostUri is correctly replaced, the connection string DbConn stays untouched. I do not even get the default value set. It keeps its value DEFINE as originally set in the Web.config.
My gut tells me my XPath /configuration/connectionStrings/add[#name='DbConn']/#connectionString is incorrect, but it looks okay to me and follows what other posts have done, such as Cobus Bernard.
Any help is greatly appreciated.
I studied log files and found that MSBuild treats connection strings differently:
...
Adding declared parameter 'HostUri'.
Adding declared parameter 'DbConn'.
Adding declared parameter 'DbConn-Web.config Connection String'.
...
The last line led to an unwanted entry in the the generated file SetParameters.xml:
...
<setParameter name="HostUri" value="Replace me!" />
<setParameter name="DbConn" value="Replace me!" />
<setParameter name="DbConn-Web.config Connection String" value="DEFINE" />
...
So my XPath was correct, but this special directive put a DEFINE into my target Web.config. I found two solutions to this, primarily based on this SO question: How to Publish Web with msbuild?
1) Tweak your project file
Unload you Web project, edit the project file and add in your desired configuration the following line:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<!-- Add this line: --
<AutoParameterizationWebConfigConnectionStrings>False</AutoParameterizationWebConfigConnectionStrings>
...
</PropertyGroup>
The build process will pick this up and stops treating connection strings special.
I find this solution too hidden and people will forget so the alternative is a bit more explicit:
2) Configure MSBuild
Pass an explicit argument to MSBuild when the release package gets built:
msbuild /P:Configuration=Release;AutoParameterizationWebConfigConnectionStrings=false;...
I'm trying to leverage Import/Export module to import taxonomies and taxonomy terms like so
<Orchard>
<Data>
<Taxonomy Id="/Identifier=Product-Categories" Status="Published">
<AutoroutePart Alias="eshop/categories" UseCustomPattern="false" />
<IdentityPart Identifier="Product-Categories" />
<TitlePart Title="Product Categories" />
<TaxonomyPart TermTypeName="ProductCategoriesTerm" />
</Taxonomy>
<ProductCategoriesTerm Id="/Identifier=Category-1" Status="Published">
<AutoroutePart UseCustomPattern="false" />
<IdentityPart Identifier="Category-1" />
<TitlePart Title="Test category" />
<TermPart Count="0" Selectable="true" Weight="1" TaxonomyId="/Identifier=Product-Categories" Path="" />
</ProductCategoriesTerm>
</Data>
</Orchard>
ProductCategoriesTerm when created through dashboard has default pattern
{Content.Container.Path}/{Content.Slug} ### my-taxonomy/my-term/sub-term
but importing terms makes them to use just {Content.Slug} ... How do I instruct AutoroutePart to use the default pattern? Tried UseCustomPattern="false" or exclude AutoroutePart with no effect it's just test-category instead of eshop/categories/test-category and won't regenerate even if if I set AutouroutePart to automatically regenerate when editing content and disable custom patterns and it won't revert to default pattern even if I try to publish it through dashboard.
Also it's mandatory to include "Count" for the TermPart when importing, does it affect anything? Sounds like something that should be dynamic and relevant only with export.
When importing taxonomy terms (and I guess any other part that has a container) it's necessary to specify Container for the common part. Without it Container for the part is null and therefore can't resolve {Content.Container.Path} in the alias pattern.
<CommonPart Container="/Identifier=Product-Categories" />
Or if it's nested term then Container is the parent term.
In ant 1.6x the condition is never true despite app.get.method=download, why doesnt this work?
<target name="-get-method">
<condition property="do.download">
<equals arg1="${app.get.method}" arg2="download" />
</condition>
<echo message="${do.download}" />
</target>
Properties in ant are global and immutable.
You have probably already set the do.download property somewhere else.
Trying printing the value of do.download BEFORE the condition element it will probably already be "false".
Is it possible to disable a <remove name="left"> statement defined in a default layout .xml file, from the local.xml file?
For example, in the checkout.xml in the <checkout_cart_index> section, the statement <remove name="left"/> is defined there, but can you disable that line from the local.xml file, so you still see the left menu on the checkout page?
By default Magento doesn't provide an <unremove /> tag for local.xml. However, the Layout system contains the right events, such that you can implement this yourself. And by "yourself", I mean I've created an experimental extension that adds such a tag. Feedback is welcome.
The two ways I do this are;
Use Alan Storm's excellent unremove plugin above.
Re insert the removed block in local.xml with a new name attribute but the same alias or 'as' attribute.
The name attribute needs to be different because Magento's <remove name="foo" /> is global - it removes all instances of <block name="foo" /> even if they are added after the remove instruction. To re add the left column, for example;
<reference name="root">
<block name="left.2" as="left" type="core/text_list">
<!-- New left column is empty, so you'll need to add your left-column blocks into it here. -->
</block>
</reference>
name="left.2" means the remove action won't kill this block, as="left" means that it will still be inserted into your template via <?php echo $this->getChildHtml('left') ?>.
Unfortunately, your newly inserted left column is empty. So you'd have to re insert any blocks in there that you want to show as well. Making Alan Storm's plugin all the more useful, I think.
When a block is removed it is not destroyed, only ignored. You might be able to 're-enable' it with:
<checkout_cart_index>
<reference name="root">
<action method="append"><block>left</block></action>
</reference>
</checkout_cart_index>
I've never used this myself and wouldn't want to, if you are making a custom theme then copy the base layout files and edit them directly just as the other answers recommend.
your answer is not to disable the removal but to add it again in your local.xml
Rather than trying to reconstruct the entire set of blocks, comment the remove inside the original XML. This will be less of a maintenance headache than trying to reconstruct the blocks and worrying about precedence of the XML files, etc.
Turn this
<remove name="left" />
Into
<!-- disabling remove because X -->
<!-- <remove name="left" /> -->