Skip to content
Khaos edited this page Apr 29, 2021 · 6 revisions

Welcome

Welcome to the serilog-settings-xml wiki. Please see sub pages for examples.

Common Rules

  1. Configuration has to be in one root element
<Serilog>
   ...
</Serilog>
  1. You can use these configuration elements:
  1. 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>
  1. XML tags and attributes are case-insensitive
<serilog>
  <using>Serilog.Sink.File</using>
  <filter name="File">
    <path>/logs/file.log</path>
  </filter>
</serilog>
  1. The Name attribute of Filter, Enrich, WriteTo, AuditTo and Destructure corelates to the extension method you would call to configure that extension
<Serilog>
  <Using>Serilog.Enrichers.Thread</Using>
  <Enrich Name="WithThreadId" />
</Serilog>
  1. All parameters you would pass to an extension method are nested tags inside the Filter, Enrich, WriteTo, AuditTo and Destructure tag
<Serilog>
  <Using>Serilog.Sinks.File</Using>
  <WriteTo Name="File">
    <Path>/logs/FileLog.log</Path>
    <RestrictedToMinimumLevel>Warning</RestrictedToMinimumLevel>
    <RollingInterval>Day</RollingInterval>
  </WriteTo>
</Serilog>
  1. 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>
  1. You also define List and Array 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)

  1. 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>
Clone this wiki locally