-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Khaos edited this page Apr 29, 2021
·
6 revisions
Welcome to the serilog-settings-xml wiki. Please see sub pages for examples.
- Configuration has to be in one root element
<Serilog>
...
</Serilog>
- You can use these configuration elements:
- You can mix all configuration elements in the root element
<Serilog>
<Using>Serilog.Sinks.File</Using>
<WriteTo Name="File">
<Path>/logs/file.log</Path>
</WriteTo>
<Using>Serilog.Expressions</Using>
<Filter Name="ByExcluding">
<Expression>Prop = 42</Expression>
</Filter>
</Serilog>
- XML tags and attributes are case-insensitive
<serilog>
<using>Serilog.Sink.File</using>
<filter name="File">
<path>/logs/file.log</path>
</filter>
</serilog>
- The
Name
attribute ofFilter
,Enrich
,WriteTo
,AuditTo
andDestructure
corelates to the extension method you would call to configure that extension
<Serilog>
<Using>Serilog.Enrichers.Thread</Using>
<Enrich Name="WithThreadId" />
</Serilog>
- All parameters you would pass to an extension method are nested tags inside the
Filter
,Enrich
,WriteTo
,AuditTo
andDestructure
tag
<Serilog>
<Using>Serilog.Sinks.File</Using>
<WriteTo Name="File">
<Path>/logs/FileLog.log</Path>
<RestrictedToMinimumLevel>Warning</RestrictedToMinimumLevel>
<RollingInterval>Day</RollingInterval>
</WriteTo>
</Serilog>
- You can use
static properties
as values. Pattern:<Namespace.Class>::<StaticProperty>, <Assembly>
<Serilog>
<Using>Serilog.Enrichers.Thread</Using>
<Enrich Name="WithProperty">
<Name>Serilog.Enrichers.ThreadNameEnricher::ThreadNamePropertyName, Serilog.Enrichers.Thread</Name>
<Value>DefaultThread</Value>
</Enrich>
</Serilog>
- You also define
List
andArray
parameters.
<Serilog>
<Using>MyAssembly</Using>
<WriteTo Name="MySink">
<ArrayParam>
<Item>1</Item>
<Item>2</Item>
<Item>3</Item>
</ArrayParam>
<WriteTo>
</Serilog>
Per rule 6, the tag <ArrayParam>
is the name of a parameter of a WriteTo extension method called MySink.
Each <Item>
will be an item in the array/list. (The name of the <Item>
tag actually doesn't matter)
- You can even define simple
Object
bindings as parameters
<Serilog>
<Using>MyAssembly</Using>
<WriteTo Name="MySink">
<ObjectParam>
<PropA>1</PropA>
<PropB>Test</PropB>
<PropC>true</PropC>
</ObjectParam>
<WriteTo>
</Serilog>