Skip to content

Commit 2eee5bb

Browse files
committed
Splits the Enrich section into Enrich and Properties, so that the top-level Enrich syntax reads consistently with WriteTo.
1 parent 4de57c7 commit 2eee5bb

File tree

3 files changed

+23
-29
lines changed

3 files changed

+23
-29
lines changed

README.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ Configuration is read from the `Serilog` section.
1313
{ "Name": "LiterateConsole" },
1414
{ "Name": "File", "Args": { "path": "%TEMP%\\Logs\\serilog-configuration-sample.txt" } }
1515
],
16-
"Enrich": {
17-
"With": ["FromLogContext", "WithMachineName", "WithThreadId"],
18-
"WithProperties": {
19-
"Application": "Sample"
20-
}
16+
"Enrich": ["FromLogContext", "WithMachineName", "WithThreadId"],
17+
"Properties": {
18+
"Application": "Sample"
2119
}
2220
}
2321
}
@@ -45,7 +43,7 @@ public class Program
4543
}
4644
```
4745

48-
The `WriteTo` and `Enrich.With` sections support the same syntax, for example the following is valid if no arguments are needed by the sinks:
46+
The `WriteTo` and `Enrich` sections support the same syntax, for example the following is valid if no arguments are needed by the sinks:
4947

5048
```json
5149
"WriteTo": ["LiterateConsole", "DiagnosticTrace"]

sample/Sample/appsettings.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
"MinimumLevel": "Debug",
55
"WriteTo": [
66
{ "Name": "LiterateConsole" },
7-
{ "Name": "File", "Args": { "path": "%TEMP%\\Logs\\serilog-configuration-sample.txt" } }
8-
],
9-
"Enrich": {
10-
"With": [
11-
"FromLogContext",
12-
"WithMachineName",
13-
"WithThreadId"
14-
],
15-
"WithProperties": {
16-
"Application": "Sample"
7+
{
8+
"Name": "File",
9+
"Args": {
10+
"path": "%TEMP%\\Logs\\serilog-configuration-sample.txt",
11+
"outputTemplate": "{Timestamp:o} [{Level}] ({Application}/{MachineName}/{ThreadId}) {Message}{NewLine}{Exception}"
12+
}
1713
}
14+
],
15+
"Enrich": ["FromLogContext", "WithMachineName", "WithThreadId"],
16+
"Properties": {
17+
"Application": "Sample"
1818
}
1919
}
2020
}

src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs

+9-13
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,17 @@ void ApplyEnrichment(LoggerConfiguration loggerConfiguration, Assembly[] configu
4848
var enrichDirective = _configuration.GetSection("Enrich");
4949
if (enrichDirective != null)
5050
{
51-
var withPropertiesDirective = enrichDirective.GetSection("WithProperties");
52-
if (withPropertiesDirective != null)
53-
{
54-
foreach (var enrichProperyDirective in withPropertiesDirective.GetChildren())
55-
{
56-
loggerConfiguration.Enrich.WithProperty(enrichProperyDirective.Key, enrichProperyDirective.Value);
57-
}
58-
}
51+
var methodCalls = GetMethodCalls(enrichDirective);
52+
CallConfigurationMethods(methodCalls, FindEventEnricherConfigurationMethods(configurationAssemblies),
53+
loggerConfiguration.Enrich);
54+
}
5955

60-
var withDirective = enrichDirective.GetSection("With");
61-
if (withDirective != null)
56+
var propertiesDirective = _configuration.GetSection("Properties");
57+
if (propertiesDirective != null)
58+
{
59+
foreach (var enrichProperyDirective in propertiesDirective.GetChildren())
6260
{
63-
var methodCalls = GetMethodCalls(withDirective);
64-
CallConfigurationMethods(methodCalls, FindEventEnricherConfigurationMethods(configurationAssemblies),
65-
loggerConfiguration.Enrich);
61+
loggerConfiguration.Enrich.WithProperty(enrichProperyDirective.Key, enrichProperyDirective.Value);
6662
}
6763
}
6864
}

0 commit comments

Comments
 (0)