NLog:: putting Line number in log file - nlog

I am beginner with NLog.
I want to save Line number along with my log entry.
1 <log content>
2 <log content>
3 <log content>
4 <log content>
.............
...........
n <log content>
where 1,2,3,.... n are line numbers in log file.

You can add the numbering in the layout property of the target. There is a built in layout renderer for counting called ${counter}
<target xsi:type="File"
name="file"
fileName="logfile.txt"
layout="${counter} ${longdate}|${level:uppercase=true}|${logger}|${message}"/>

Related

find xml-nodes by tag with wildcard

I am trying to find any nodes in a xml whos tags start with a certain pattern.
<data>
<general>
<va value="400" /> <!--looking for this "v-tag"-->
<vb value="42" /> <!-- and this one-->
<y value="43" />
</general>
<special>
<va value="100" />
</special>
</data>
I cannot put together the xpath expression. Something like this
xyz = lxml.etree.parse( ... )
vees = xyz.xpath("general/[tag='v*']")
I would like to have vees beeing
vees
Out[64]: [<Element va at 0x....>, <Element vb at 0x...>]
Try changing:
vees = xyz.xpath("general/[tag='v*']")
to
doc.xpath('//general//*[starts-with(name(),"v")]')
and see if it works.

Best way to change xml values in puppet

I would like to change values in domain.xml ( JBoss Configuration file ). Please suggest me the best way to do it with sample examples to change it.
I have found the following ways. But No idea, How to use the following functions for xml files.
( i ) inline_template
( ii ) regsubst
I have to change the following four property as per each group. For Each Group, values of the 4 properties will be changed. Please suggest me the best Industry practise standard.
<system-properties>
<property name="jboss.default.multicast.address" value="230.0.1.1" boot-time="true"/>
<property name="modcluster.balancer.name" value="mylb" boot-time="true"/>
<property name="modcluster.proxylist" value="172.28.168.153:6777" boot-time="true"/>
<property name="mycluster.modcluster.lbgroup" value="coollb" boot-time="true"/>
</system-properties>
inline_template are executed on master, so they won't solve your problem.
The easiest solution is erb templates. But this means that you will control from puppet the entire file, not only the properties.
The best solution: there seems to be an augeas lens for xml: https://twiki.cern.ch/twiki/bin/view/Main/TerjeAndersenAugeas
Edit:
have an erb template in your module (templates/jboss_config.xml.erb)
<bla bla>....
<system-properties>
<property name="jboss.default.multicast.address" value="<%= #multicast_address %>" boot-time="true"/>
<property name="modcluster.balancer.name" value="<%= #balancer_name %>" boot-time="true"/>
<property name="modcluster.proxylist" value="<%= #proxylist %>" boot-time="true"/>
<property name="mycluster.modcluster.lbgroup" value="<%= #lbgroup %>" boot-time="true"/>
</system-properties>
</bla bla>....
In your puppet class declare the parameters/variables (those can came from hiera also, if you want to do overwrites based on some facts):
$multicast_address = '230.0.1.1'
$balancer_name = 'mylb'
$proxylist = '172.28.168.153:6777'
$lbgroup = 'coollb'
# and write your file:
file { 'jboss_config_file':
ensure => file,
path => '/path/to/jboss/config/file.xml',
content => template("${module_name}/jboss_config.xml.erb"),
}

How can i create a hierarchical dimension for dates in ActivePivot?

I'm a newbe in ActivePivot and i want to create a dimension with DimensionType = time, where the dates a shown in hierachical manner. E.g. for 30.01.2013 i need one level for the year -> 2013 (sort descending), one level for the month (also sort descending) -> 1 and one level for the days (also sort descending) -> 30, 29, 28, ...
Viewed via ActivePivotLive should look like:
- 2013
- 1
- 30
- 29
- 28
- ...
+ 2012
+ 2011
and so on.
I went through the ActivePivot sandbox project, but i didn't find anything that helps me. The TimeBucket dimension which i've found in the EquityDerivativesCube makes something similar but the buckets are created in a different manner.
How can i solve this problem?
Ok, i handle it out.
It is not necessary to make the round trip and to implement a dimension. It is easy done by levels and the a calculator.
Here the code from the EquityDerivativesCube.xml
<!-- Standard time buckets, bucketing performed at insertion -->
<dimension name="TimeBucket">
<properties>
<entry key="DimensionType" value="time" />
<entry key="IsAllMembersEnabled" value="true" />
</properties>
<level name="Year">
<properties>
<entry key="LevelType" value="TIME_YEARS" />
</properties>
<comparator pluginKey="ReverseOrder" />
</level>
<level name="Month">
<properties>
<entry key="LevelType" value="TIME_MONTHS" />
</properties>
<comparator pluginKey="Custom">
<order name="firstObjects">
<value>Jan</value>
<value>Feb</value>
<value>Mrz</value>
<value>Apr</value>
<value>Mai</value>
<value>Jun</value>
<value>Jul</value>
<value>Aug</value>
<value>Sep</value>
<value>Okt</value>
<value>Nov</value>
<value>Dez</value>
</order>
</comparator>
</level>
<!-- The Value Date level is the field Date -->
<level name="Value Date" property="Date">
<properties>
<entry key="LevelType" value="time" />
</properties>
<comparator pluginKey="ReverseOrder" />
</level>
</dimension>
I added the following snippet to PNLCalculator.enrichTrade:
...
pnl = pnlVega + pnlDelta;
// Year and month calculations BEGIN
final Calendar cal = CALENDAR.get();
cal.setTime(trade.getDate());
final int year = cal.get(Calendar.YEAR);
final String month = DateFormatSymbols.getInstance(GERMANY).getShortMonths()[cal.get(MONTH)];
// Year and month calculations END
// instantiate the result that will hold the enrichment data
final PNLCalculatorResult result = new PNLCalculatorResult();
...
// add them to the result
result.setYear(year);
result.setMonth(month);
...
I also extended the SanboxFields.xml with the two new fields:
...
<field name="Year" type="integer" />
<field name="Month" type="string" />
...
Cheers!
The TimeBucket dimension in the ActivePivot Sandbox application defines a custom bucketing based on financial time periods. Creating a standard year > month > day hierarchy is actually simpler and seamless in ActivePivot. In the description if the schema you need to declare three fields (one for year, one for month and one for the day).
<field name="Year" indexation="dictionary" />
<field name="Month" indexation="dictionary" />
<field name="Day" indexation="dictionary" />
And then you need to declare a dimension that references those fields.
<dimension name="Time">
<level name="Year" />
<level name="Month" />
<level name="Day" />
</dimension>
Then ActivePivot will build the time hierarchy incrementally, by introspecting the loaded records.
This will work automagically if the input records (objects) already contain a Year attribute, a Month attribute and a Day atribute (For instance if the input records are POJOs with getYear(), getMonth() and getDay() methods). If that is not the case and that for instance the input records only have a date attribute, you can either transform your records before puutting them into ActivePivot, or inject a calculator in ActivePivot (com.quartetfs.biz.pivot.classification.ICalculator) that will on the fly compute the three fields from the date. Look at the ActivePivot Sandbox application for an example of calculator.
Extracting those fields is usually done with standard Java code:
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
System.out.println("Date: " + date);
System.out.println("Year: " + calendar.get(Calendar.YEAR));
System.out.println("Month: " + calendar.get(Calendar.MONTH) + 1);
System.out.println("Day: " + calendar.get(Calendar.DAY_OF_MONTH));
About the ordering of members in the level of a dimension, ActivePivot per default uses the natural ordering of java objects (those that implement java.lang.Comparable interface) so dates and integers will be sorted from the lowest to the greatest. You can easily reverse that by declaring a "ReverseOrder" comparator on the target level(s).
<dimension name="Time">
<level name="Year">
<comparator pluginKey="ReverseOrder" />
</level>
<level name="Month">
<comparator pluginKey="ReverseOrder" />
</level>
<level name="Day">
<comparator pluginKey="ReverseOrder" />
</level>
</dimension>

Build a string in MSBuild as a concatenation of a base string n-times

I have a numer, "n" in a property in MSBuild. I also have a string "Str" that needs to be duplicated n-times to achieve a final string that is the repetition of "Str" n times.
Eg. If n is 3 and Str is "abc", what I want to obtain is "abcabcabc"
Since one cannot loop in MSBuild, I don't know how to achieve this. Perhaps with an item group, but how do I create one based on a property containing an "n" count?
Thanks!
To create a String repeated n times, you can also do this (at least in MSBuild Tools v4.0):
<SomeRepeatedString>$([System.String]::New("-", 40))</SomeRepeatedString>
usually for things like this I resolve to using inline C#, as it costs me less time than searching all over the internet to find a 'true' msbuild solution; here you go:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MyString>abc</MyString>
<Count>3</Count>
</PropertyGroup>
<UsingTask TaskName="RepeatString" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<s ParameterType="System.String" Required="true" />
<n ParameterType="System.Int32" Required="true" />
<result ParameterType="System.String" Output="true" />
</ParameterGroup>
<Task>
<Code Type="Fragment" Language="cs"><![CDATA[
result = string.Concat( Enumerable.Repeat( s, n ) );
]]></Code>
</Task>
</UsingTask>
<Target Name="doit">
<RepeatString s="$(MyString)" n="$(Count)">
<Output PropertyName="result" TaskParameter="result" />
</RepeatString>
<Message Text="Result = $(result)"/>
</Target>
</Project>

how to do for loop based on a limit in Ant

In Ant-contrib, we can do something like:
<for list="a,b,c,d" param="instence">
But if I don't have a list, I only have a limit, e.g. limit=4.
Is there a way to do for loop based on limit, like:
<for limit="4" param="index">
<project name="Attachments" default="print">
<property name="numAttachments" value="20" />
<target name="generate">
<script language="javascript"><![CDATA[
var list = '1';
var limit = project.getProperty( "numAttachments" );
for (var i=2;i<limit;i++)
{
list = list + ',' + i;
}
project.setNewProperty("list", list);
]]>
</script>
</target>
<target name="print" depends="generate">
<for list="${list}" param="letter">
<sequential>
<echo>Letter #{letter}</echo>
</sequential>
</for>
</target>
</project>
Its not exactly what you want, but this page has an example. Essentially, you pass in the limit as a list of numbers. Its not elegant, but it works.
Here's another idea - see the answer by user "cn1h". Its a cool way to get around limitations in ANT - embed a script from another language which can do what you want. Nice!
In antcontrib you can also do:
<for param="index" end="#{numberOfIterations}" start="1">
But be aware of a bug: It is unable to handle
begin and end being the same. So when "numberOfIterations" equals 1 you get an error.
We got a workaround for this, checking the value of numberOfIterations first and only when its not 1 doing the for-statement.
<if><equals arg1="1" arg2="#{numberOfIterations}"/>
<then>
....
</then>
<else>
<for param="index" end="#{numberOfIterations}" start="1">
....
</else>
</if>
The Ant addon Flaka provides some solutions for your problem.
1) Use a while loop
the test attribute evaluates some EL expression, which maybe a simple counter, f.e.
<project name="demo" xmlns:fl="antlib:it.haefelinger.flaka">
<!-- some counter -->
<fl:let>
countdown = 3
</fl:let>
<fl:while test=" countdown >= 0 ">
<fl:echo>
#{countdown > 0 ? countdown : 'bang!' }..
</fl:echo>
<fl:let>
countdown = countdown - 1
</fl:let>
</fl:while>
</project>
output:
[fl:echo] 3..
[fl:echo] 2..
[fl:echo] 1..
[fl:echo] bang!..
or some other expression, f.e. checking for existence of a file, means looping until some file exists :
<fl:while test=" !'/home/rosebud/stop'.tofile.isfile ">
<fl:echo>
still working..
</fl:echo>
</fl:while>
2) Use a for loop with break or continue :
<project name="demo" xmlns:fl="antlib:it.haefelinger.flaka">
<fl:for var="i" in=" list(1,2,3,4,5,6) ">
<fl:echo>i = #{i}</fl:echo>
<fl:break test=" i == 3 " />
</fl:for>
<fl:for var="i" in=" list(1,2,3,4,5,6) ">
<fl:continue test=" i > 3 " />
<fl:echo>i = #{i}</fl:echo>
</fl:for>
</project>
which gives the same result :
[fl:echo] i = 1
[fl:echo] i = 2
[fl:echo] i = 3
See more details in the Flaka manual

Resources