Skip to content

A Serilog settings provider that reads from XML sources with zero dependencies and full configuration support

License

Notifications You must be signed in to change notification settings

serilog-contrib/serilog-settings-xml2

Repository files navigation

Serilog.Settings.XML2

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.

Syntax and structure

Please have a look in the Wiki for information about the XML structure and capabilities of this provider

Acknowledgement

This project depends heavily on the sources of Serilog.Settings.Configuration

About

A Serilog settings provider that reads from XML sources with zero dependencies and full configuration support

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages