Skip to content

Commit 0e77b18

Browse files
authored
Add more documentation to the README (duplicates the wiki content for now) [Skip CI]
1 parent 589b56c commit 0e77b18

File tree

1 file changed

+106
-2
lines changed

1 file changed

+106
-2
lines changed

README.md

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,107 @@
1-
# Serilog.Settings.AppSettings [![Build status](https://ci.appveyor.com/api/projects/status/lpkpthfap819flva?svg=true)](https://ci.appveyor.com/project/serilog/serilog-settings-appsettings)
1+
# Serilog.Settings.AppSettings [![Build status](https://ci.appveyor.com/api/projects/status/lpkpthfap819flva?svg=true)](https://ci.appveyor.com/project/serilog/serilog-settings-appsettings) [![NuGet Version](http://img.shields.io/nuget/v/Serilog.Settings.AppSettings.svg?style=flat)](https://www.nuget.org/packages/Serilog.Settings.AppSettings/) [![Join the chat at https://gitter.im/serilog/serilog](https://img.shields.io/gitter/room/serilog/serilog.svg)](https://gitter.im/serilog/serilog)
22

3-
The XML `<appSettings>` reader for [Serilog](https://serilog.net). See the [documentation](https://github.com/serilog/serilog/wiki/AppSettings) for more information.
3+
An XML `<appSettings>` reader for [Serilog](https://serilog.net).
4+
5+
### Getting started
6+
7+
The `<appSettings>` support package needs to be installed from NuGet:
8+
9+
```powershell
10+
Install-Package Serilog.Settings.AppSettings
11+
```
12+
13+
To read configuration from `<appSettings>` use the `ReadFrom.AppSettings()` extension method on your `LoggerConfiguration`:
14+
15+
```csharp
16+
Log.Logger = new LoggerConfiguration()
17+
.ReadFrom.AppSettings()
18+
... // Other configuration here, then
19+
.CreateLogger()
20+
```
21+
22+
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 app settings.
23+
24+
### Configuration syntax
25+
26+
To configure the logger, an `<appSettings>` element should be included in the program's _App.config_ or _Web.config_ file.
27+
28+
```xml
29+
<?xml version="1.0" encoding="utf-8" ?>
30+
<configuration>
31+
<appSettings>
32+
<add key="serilog:minimum-level" value="Verbose" />
33+
<!-- More settings here -->
34+
```
35+
36+
Serilog settings are prefixed with `serilog:`.
37+
38+
### Setting the minimum level
39+
40+
To set the logging level for the app use the `serilog:minimum-level` setting key.
41+
42+
```xml
43+
<add key="serilog:minimum-level" value="Verbose" />
44+
```
45+
46+
Valid values are those defined in the `LogEventLevel` enumeration: `Verbose`, `Debug`, `Information`, `Warning`, `Error`, `Fatal`.
47+
48+
### Adding a sink
49+
50+
Sinks are added with the `serilog:write-to` key. The setting name matches the configuration method name that you'd use in code, so the following are equivalent:
51+
52+
```csharp
53+
.WriteTo.LiterateConsole()
54+
```
55+
56+
In XML:
57+
58+
```xml
59+
<add key="serilog:write-to:LiterateConsole" />
60+
```
61+
62+
**NOTE: When using `serilog:*` keys need to be unique.**
63+
64+
Sink assemblies must be specified using the `serilog:using` syntax. For example, to configure
65+
66+
```csharp
67+
<add key="serilog:using:LiterateConsole" value="Serilog.Sinks.Literate" />
68+
<add key="serilog:write-to:LiterateConsole"/>
69+
```
70+
71+
If the sink accepts parameters, these are specified by appending the parameter name to the setting.
72+
73+
```csharp
74+
.WriteTo.RollingFile(@"C:\Logs\myapp-{Date}.txt", retainedFileCountLimit: 10)
75+
```
76+
77+
In XML:
78+
79+
```xml
80+
<add key="serilog:write-to:RollingFile.pathFormat" value="C:\Logs\myapp-{Date}.txt" />
81+
<add key="serilog:write-to:RollingFile.retainedFileCountLimit" value="10" />
82+
```
83+
84+
Any environment variables specified in a setting value (e.g. `%TEMP%`) will be expanded appropriately when read.
85+
86+
### Using sink extensions from additional assemblies
87+
88+
To use sinks and enrichers from additional assemblies, specify them with a `serilog:using` key.
89+
90+
For example, to use configuration from the `Serilog.Sinks.EventLog` assembly:
91+
92+
```xml
93+
<add key="serilog:using:EventLog" value="Serilog.Sinks.EventLog" />
94+
<add key="serilog:write-to:EventLog.source" value="Serilog Demo" />
95+
```
96+
97+
### Enriching with properties
98+
99+
To attach additional properties to log events, specify them with the `serilog:enrich:with-property` directive.
100+
101+
For example, to add the property `Release` with the value `"1.2-develop"` to all events:
102+
103+
```xml
104+
<add key="serilog:enrich:with-property:Release" value="1.2-develop" />
105+
```
106+
107+
See the [Serilog documentation](https://github.com/serilog/serilog/wiki/AppSettings) for further information.

0 commit comments

Comments
 (0)