Skip to content

serilog-contrib/serilog-settings-xml

Repository files navigation

Serilog.Settings.Xml Build status NuGet

An XML config reader for Serilog.

Motivation

XML based configuration can be more suitable for some projects, because:

  • xml transformations can be used
  • out of the box support in MS Deploy and Octopus Deploy
  • configuration consistency in leagacy (not .NET Core) projects

Getting started

The package needs to be installed from NuGet:

Install-Package Serilog.Settings.Xml

To read configuration from xml configuration file use the ReadFrom.Xml(filePath) extension method on your LoggerConfiguration:

Log.Logger = new LoggerConfiguration()
  .ReadFrom.Xml("serilog.config")
  ... // Other configuration here
  .CreateLogger()

You can mix and match XML and code-based configuration, but each sink must be configured either using XML or in code - sinks added in code can't be modified via config file.

Configuration sample

<?xml version="1.0" encoding="utf-8" ?>

<serilog>

    <using>
        <add name="Serilog.Enrichers.Thread" />
        <add name="Serilog.Enrichers.Process" />
        <add name="Serilog.Enrichers.Environment" />
        <add name="Serilog.Sinks.File" />
    </using>

    <enrich>
        <enricher name="FromLogContext" />
        <enricher name="WithMachineName" />
        <enricher name="WithThreadId" />
        <enricher name="WithProcessId" />
        <enricher name="WithEnvironmentUserName" />
    </enrich>

    <properties>
        <property name="Application" value="Sample" />
        <property name="Path" value="%PATH%" />
    </properties>

    <minimumLevel default="Information">
        <override name="Microsoft" level="Warning" />
        <override name="Microsoft.AspNetCore.Mvc" level="Error" />
    </minimumLevel>

    <writeTo>
        <sink name="File">
            <arg name="path" value="%TEMP%/Logs/serilog-configuration-sample.txt" />
        </sink>
    </writeTo>

</serilog>

About

Xml file based configuration for Serilog (https://serilog.net)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy