Custom Targets, layout etc. could have properties. When configuring from the XML config, there are some limitations on the types.
Supported types for Targets, Layouts and Layout renderers:
Encoding
CultureInfo
Type
LineEndingMode
Uri
Layout
, SimpleLayout
& ConditionExpression
string
TypeDescriptor
from string
Introduced in NLog 4.4, collection types could be used.
Usage in XML: comma separated string. If the value contains a comma, single quote the whole value.
Examples:
value="one arg"
value="1,2"
value="value1,'value2, with comma'"
Supported types:
IList<T>
/ IList
IEnumerable<T>
/ IEnumerable
ISet<T>
/ HashSet<T>
with the following types:
Not supported:
List
IList
PS: .NET 3.5 hasn't ISet<T>
, so use HashSet<T>
For targets and layout renderers there is also support for XML elements.
E.g. the JSON layout:
<target name="jsonFile" xsi:type="File" fileName="${logFileNamePrefix}.json"> <layout xsi:type="JsonLayout"> <attribute name="time" layout="${longdate}" /> <attribute name="level" layout="${level:upperCase=true}"/> <attribute name="message" layout="${message}" /> </layout> </target>
Usage in C#
[ArrayParameter(typeof(JsonAttribute), "attribute")] public IList<JsonAttribute> Attributes { get; private set; } [NLogConfigurationItem] public class JsonAttribute {} //needs default ctor
Another example is the Database target
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