A Serilog settings provider that reads from XML sources, like XML files
or XElement. This is a fork of the Serilog.Settings.Configuration and supoorts most of its use cases, but with much less dependencies.
By default, the configuration is read from the root element of a XML file
.
<Serilog>
<Using>Serilog.Sinks.Console</Using>
<Using>Serilog.Sinks.File</Using>
<MinimumLevel>Debug</MinimumLevel>
<WriteTo Name="Console" />
<WriteTo Name="File">
<Path>Logs/log.txt</Path>
</WriteTo>
<Enrich Name="FromLogContext" />
<Enrich Name="WithMachineName" />
<Enrich Name="WithThreadId" />
<Destructure Name="With">
<Policy>Sample.CustomPolicy, Sample</Policy>
</Destructure>
<Destructure Name="ToMaximumDepth">
<MaximumDestructuringDepth>4</MaximumDestructuringDepth>
</Destructure>
<Destructure Name="ToMaximumStringLength">
<MaximumStringLength>100</MaximumStringLength>
</Destructure>
<Destructure Name="ToMaximumCollectionCount">
<MaximumCollectionCount>10</MaximumCollectionCount>
</Destructure>
<Property Name="Application" Value="Sample" />
</Serilog>
After installing this package, use ReadFrom.XML()
and pass a path to a XML file
or a XElement object as the root element to read from.
static void Main(string[] args)
{
var logger = new LoggerConfiguration()
.ReadFrom.XML("config.xml")
.CreateLogger();
logger.Information("Hello, world!");
}
This example relies on the Serilog.Sinks.Console, Serilog.Sinks.File, Serilog.Enrichers.Environment and Serilog.Enrichers.Thread packages also being installed.
Please have a look in the Wiki for information about the XML structure and capabilities of this provider
This project depends heavily on the sources of Serilog.Settings.Configuration