I'm trying to use ThreadContext to add some extra parameters into the log lines. It works fine however when some of the parameters are not initialized log4net prints "(null)" in the output:
DEBUG|0327-133110600|CurrentAppDomainHost.ExecuteNodes|logger|(null)|(null)|(null)|127.0.0.1|(null)|test
my pattern:
%-5p|%d{MMdd-HHmmssfff}|%t|%c{2}|%X{aCode}|%X{bCode}|%X{cCode}|%X{dCode}|%X{eCode}|%m%n
is there a way to use just an empty string instead of those (null) and not setting them explicitly?
Yes, you can set the following in app/web.config:
<appSettings>
<add key="log4net.NullText"
value="" />
</appSettings>
Related
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 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>
My source xml looks like this :
<connectionStrings>
<clear />
<add name="StrConn" providerName="SQLNCLI10"
connectionString="Server=dbserver;Database=db;User Id=user;Password=pass;" />
</connectionStrings>
Notice the seemingly innocent <clear /> tag.
Once I've imported this xml, and made changes to the xml file i.e: the connection string. All single tags in the document like <add /> or <clear /> are rewritten to long form eg: <clear></clear> and this prevents my service / app from even running.
It seems crazy since ultimately it seems like valid XML, but yeah it dies with an unknown fault exception, but when replacing the clear tags to all be <clear /> and not <clear ></clear> it works.
How can I prevent installshield from transforming these tags?
Are you using the 'update xml' feature? Try using the 'udpate text file' instead. That's a bit ugly to use for xml files but it works (we've been using it before the update xml feature was introduced)
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" /> -->
When using a Log4J RollingFileAppender on Websphere 7.0, how can I specify the location of the logging directory in the log4j.properties file, i.e. pick up Websphere's LOG_ROOT variable?
You have an option of specifying a JVM Custom property which can use the WebSphere variables.
The JVM Custom property can be used in your log4j.properties.
Find below some instructions on achieving the same:
In the admin console the path would be:
Application servers > Your Server Name > Process Definition > Java Virtual Machine > Custom Properties
The Customer property can use a WebSphere variable as the value for our custom property - KeyForMyCustomProperty. The WebSphere variable would use the standard pattern: ${}
E.g ${MY_VARIABLE}.
The log4j properties files could access this custom property via
log4j.appender.messageAppender.File=${KeyForMyCustomProperty}/Message.log
This approach is not straightforward but achieves the desired results. You can choose to use the same key as the WebSphere variable for the JVM Custom Property then it appears as-if the WebSphere variable is used in the log4j.properties
HTH
Manglu
Of course, it would be trivially simple to write a custom subclass of RollingFileAppender that programatically determines the LOG_ROOT variable value, in a platform-independent way.
It would likely only require about a dozen lines of code, if that. Then follow up with,
<appender name="CustomAppender" class="path.to.your.CustomAppender">
<param name="File" value="fileNameOnly.out" />
<param name="Append" value="true" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n" />
</layout>
</appender>
and let the subclass accept the File parameter, derive the LOG_ROOT path, and append it to the file name before calling super class methods.
I hope that helps in some way,
-gMale