Does Nlog variables store the same value until the session end - nlog

I am passing exception message via variable
LogManager.Configuration.Variables["Exception"] = exception.ToString();
nlog.config
<variable name="Exception" />
<column name="EXCEPTION MESSAGE" layout="${var: Exception}" />
In log file, I created a custom nlog class where I am passing few values through variable as I mentioned above. If first time I got an exception then it is writing on log file again and again every next lines although there is no exception in next lines in same session until we get 2nd exception. And then 2nd exception is rewriting in all next lines.
How can I solve this? Is there any way that I can kill the previous variable value?

You should not store exceptions (or other context-information) in the NLog-Config-Variables.
Instead you should do this:
logger.Error(exception, "Something bad happened");
And modify your config to this:
<column name="EXCEPTION MESSAGE" layout="${exception:format=tostring}" />
<column name="EXCEPTION TYPE" layout="${exception:format=type}" />
<column name="EXCEPTION TARGETSITE" layout="${exception:format=Method}" />
See also https://github.com/NLog/NLog/wiki/Context and https://github.com/NLog/NLog/wiki/Exception-layout-renderer

Related

kendo-react-ui "Uncaught TypeError: Cannot read properties of undefined (reading 'displayName')"

I am using Kendo-react library in my React project.
I am try to render a table with the Grid component
but in the browser I don't see anything and in the console i get error:
"Uncaught TypeError: Cannot read properties of undefined (reading 'displayName')".
Has anyone encountered this error?
this is the code:
<Grid
// total={productsExample.length}
// data={orderBy(productsExample, sort)}
// sortable={true}
// sort={sort}
// onSortChange={columnSort}
>
<GridColumn className="AAAAAAA" title="some title" field="SubmittingID" width='120px' />
<GridColumn title="RequestID" field="RequestID" />
<GridColumn title="Address" field="AddressName" />
<GridColumn title="Rounds Number" field="RoundsNumber" />
<GridColumn title="Last Delivery Date" field="LastDeliveryDate" /> {/* check sort by dates - not sorting */}
<GridColumn title="Date Of Department Notes" field="DateOfDepartmentNotes" /> {/* check sort by dates - not sorting */}
<GridColumn title="Notes" field="Notes" />
<GridColumn title="Responsible" field="Responsible" />
</Grid>
and screenshot is here:
enter image description here
and this what i am see in the console:
enter image description here
After a few hours of research,
I debug the code in the console and i see something weird.
I have 8 celles and instade of 8 cells i see 10 and 2 of them was empty quotes,
and suddenly i realized that is the 2 lines that i put in comment,
so i removed them and i got the table.
Another thing that i understood if i put the comments in new line and i got the table.
Probably if the comments are in the same line of some cell
the compiler think that the comments are part of the cell and try to render them

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.

spring integration xpath namespace issue

I am trying to use an an xpath expression, in order to read requestId field in the xml file given below. however, this expression results in no matches. When I try to enclose the field names with single quotes, it results in a compilation error. I even tried using local-name, instead of name, in the xpath expression. I need to be able to get the value of requestId field as shown.
<int-file:outbound-channel-adapter
id="file" mode="APPEND" charset="UTF-8"
directory="C:\\Users\\dvenkat1\\Desktop\\test"
auto-create-directory="true" filename-generator-expression="#xpath(payload, '/*[name()=Envelope]/*[name()=Body]/*[name()=processArchiveRequest]/*[name()=fulfillmentRequest]/*[name()=requestHeader]/*[name()=requestID]/text()')" />
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:sch="http://...schema">
<soap:Header/>
<soap:Body>
<sch:processArchiveRequest>
<sch:fulfillmentRequest>
<sch:requestHeader>
<sch:requestID>Samplereq</sch:requestID>
............
Another option would be, is to use something like this:
<int-file:outbound-channel-adapter
id="file" mode="APPEND" charset="UTF-8"
directory="C:\\Users\\dvenkat1\\Desktop\\test"
auto-create-directory="true" filename-generator-expression="#xpath(payload, 'reference exp1 here']) " />
<int-xml:xpath-expression id = "exp1"
expression="name(/soapNs:Envelope/soapNs:Body/schNs:processArchiveRequest/schNs: fulfillmentRequest/schNs:requestDetail/*[1])"
namespace-map="archiveNamespaceMap" />
<util:map id="archiveNamespaceMap">
<entry key="soapNs" value="http://www.w3.org/2003/05/soap-envelope" />
<entry key="schNs" value="http://blah../schema" />
</util:map>
It works for me like this:
filename-generator-expression="#xpath(payload, '//*[local-name()="requestID"]')"
Pay attention to the escaped " symbol.
Regarding <int-xml:xpath-expression>.
You can use it from the the filename-generator-expression as well, but you should follow with the XPathExpression and therefore use XmlPayloadConverter manually. And do that everything somewhere from the custom bean.

Sharepoint Custom Field Render Pattern: Render to multiple fields

Initial Question
Can I render the data from one field into multiple columns?
Background
I have created a custom field that contains a drop down list and two text boxes. The idea is that users can select a supplier from the drop down list that is connected to a list of suppliers. Which will get the contact name and number of the supplier and populate the corresponding textboxes.
I have done it this way as it is important to be able to override the contact number and the address but the client wants to see the defaults.
Heres what it looks like:
On saving the new entry the value of the field is saved as follows:
;#1;#Supplier 1;#Contact Name;#01234 567890;#
I chose to save the data in this was so I can treat it like a multi-column field when I render it.
I am using the below code to split the data and override the display pattern for the list view:
<RenderPattern Name="DisplayPattern">
<Switch>
<Expr>
<Column />
</Expr>
<Case Value="" />
<Default>
<!--<Column SubColumnNumber="0" HTMLEncode="TRUE" />
<HTML><![CDATA[<br/>]]></HTML>-->
<Column SubColumnNumber="1" HTMLEncode="TRUE" />
<HTML><![CDATA[ - ]]></HTML>
<Column SubColumnNumber="2" HTMLEncode="TRUE" />
<HTML><![CDATA[ - ]]></HTML>
<Column SubColumnNumber="3" HTMLEncode="TRUE" />
<HTML><![CDATA[]]>]></HTML>
</Default>
</Switch>
</RenderPattern>
This allows me to present the data to the end user as follows:
Question
I would like to be able to display this split data in seperate columns. I notice that the build in title field SharePoint uses has four types of columns you can add to a view for a single field. I am trying to reproduce this kind of functionality so each section of the data can be added or removed from views. Is this possible?
It turns out you have access the list item which meant I was able to simply just add to additional fields within the list item by overriding the UpdateFieldValueInItem method.
Public Overrides Sub UpdateFieldValueInItem()
Me.ItemFieldValue = ddlSupplier.SelectedItem.Value
If Me.Item.Fields.ContainsField(Me.Field.InternalName & "-" & "Telephone") Then
Me.Item(Me.Field.InternalName & "-" & "Telephone") = txtTelephone.Text
End If
End Sub
A much more effective way of doing this.

access ant property value for pattern variable in file.eachFileMatch() in Groovy

I am unable to run the code for moving file, when i use the ant macrodef attribute in groovy task inside the macrodef.
<macrodef name="dirmove">
<attribute name="todir" />
<attribute name="fromdir" />
<attribute name="includes" default="*" />
<sequential>
<var name="todir" value="#{todir}" />
<var name="fromdir" value="#{fromdir}" />
<var name="includes" value="#{includes}" />
<groovy>
File dir1 = new File(properties.'fromdir');
File dir2 = new File(properties.'todir');
def pattern = properties.get('includes')
println pattern;
dir1.eachFileMatch ~/pattern/, {
f->
boolean fileMoved = f.renameTo(new File(dir2, f.getName()));
//assert f.name == '1.txt' //**because File object is immutable, so I am just checking for the existing of previous file name. It is still there.
println fileMoved;
}
</groovy>
</sequential>
</macrodef>
This code correctly prints the value of pattern, which is coming from attribute value. But the eachFileMatch function doesn't picks up the spec
dir1.eachFileMatch ~/pattern/, {
should be
dir1.eachFileMatch ~/${pattern}/, {
As pattern is a String variable, so you need to add it in to the regex pattern as such.
Previously, you were just searching for all files called pattern

Resources