A specialized layout that renders CSV-formatted events.
Platforms Supported: All
<targets> <target> <layout xsi:type="CsvLayout"> <!-- CSV Columns --> <column layout="Layout" name="String"/> <!-- repeated --> <!-- CSV Options --> <quoting>Enum</quoting> <quoteChar>String</quoteChar> <withHeader>Boolean</withHeader> <customColumnDelimiter>String</customColumnDelimiter> <delimiter>Enum</delimiter> </layout> </target> </targets>
Array-collection where each item is represented by <column />
element with the following attributes:
Introduced with NLog 4.6
quoting - Default Quoting mode for columns to ensure valid CSV output. Default: Auto
Possible values:
quoteChar - Quote Character. Default: "
withHeader - Indicates whether CSV should include header. Boolean
. Default true
customColumnDelimiter - Custom column delimiter value (valid when delimiter
is set to Custom
).
delimiter - Column delimiter. Default: Auto
Possible values:
,
character (ASCII 44).CustomColumnDelimiter
.|
character (ASCII 124).;
character (ASCII 59).<target xsi:type="File" name="csvFileExample" fileName="./CsvLogExample.csv"> <layout xsi:type="CsvLayout" delimiter="Tab" withHeader="false"> <column name="time" layout="${longdate}" /> <column name="level" layout="${level:upperCase=true}"/> <column name="message" layout="${message}" /> <column name="exception" layout="${exception:format=ToString}"/> <column name="property1" layout="${event-properties:property1}"/> </layout> </target>
NLog 4.6 introduces some performance optimizations for the CsvLayout. Reducing memory allocation by better buffer reuse. It is also possible to reduce the overhead of the automatic quoting logic for individual columns:
This is example will greatly reduce the overhead of default Auto-quoting, because of the override for the individual columns:
<layout xsi:type="CsvLayout" delimiter="Tab" withHeader="false"> <column name="time" layout="${longdate}" quoting="Nothing" /> <column name="level" layout="${level:upperCase=true}" quoting="Nothing"/> <column name="message" layout="${message}" quoting="All" /> <column name="exception" layout="${exception:format=ToString}" quoting="All"/> <column name="property1" layout="${event-properties:property1}"/> </layout>
Layout = new CsvLayout() { Columns = { new CsvColumn("time", "${longdate}"), new CsvColumn("level", "${level:upperCase=true}"), new CsvColumn("message", "${message}"), new CsvColumn("exception", "${exception:format=ToString}"), new CsvColumn("property1", "${event-properties:property1}"), } }
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4