1
- using System . Globalization ;
2
1
using System . Reflection ;
3
2
using Microsoft . Extensions . Configuration ;
4
3
using Serilog . Events ;
@@ -16,17 +15,18 @@ public class ConfigurationReaderTests
16
15
public ConfigurationReaderTests ( )
17
16
{
18
17
_configurationReader = new ConfigurationReader (
19
- JsonStringConfigSource . LoadSection ( "{ ' Serilog' : { } }" , "Serilog" ) ,
18
+ JsonStringConfigSource . LoadSection ( "{ \" Serilog\" : { } }" , "Serilog" ) ,
20
19
AssemblyFinder . ForSource ( ConfigurationAssemblySource . UseLoadedAssemblies ) ,
21
20
new ConfigurationReaderOptions ( ) ) ;
22
21
}
23
22
24
23
[ Fact ]
25
24
public void WriteToSupportSimplifiedSyntax ( )
26
25
{
26
+ // language=json
27
27
var json = """
28
28
{
29
- ' WriteTo' : [ ' LiterateConsole', ' DiagnosticTrace' ]
29
+ " WriteTo" : [ " LiterateConsole", " DiagnosticTrace" ]
30
30
}
31
31
""" ;
32
32
@@ -42,10 +42,11 @@ public void WriteToSupportSimplifiedSyntax()
42
42
[ Fact ]
43
43
public void WriteToSupportExpandedSyntaxWithoutArgs ( )
44
44
{
45
+ // language=json
45
46
var json = """
46
47
{
47
- ' WriteTo' : [ {
48
- ' Name': ' LiterateConsole'
48
+ " WriteTo" : [ {
49
+ " Name": " LiterateConsole"
49
50
}]
50
51
}
51
52
""" ;
@@ -60,13 +61,14 @@ public void WriteToSupportExpandedSyntaxWithoutArgs()
60
61
[ Fact ]
61
62
public void WriteToSupportExpandedSyntaxWithArgs ( )
62
63
{
64
+ // language=json
63
65
var json = """
64
66
{
65
- ' WriteTo' : [ {
66
- ' Name': ' LiterateConsole' ,
67
- ' Args' : {
68
- ' outputTemplate': ' {Message}'
69
- },
67
+ " WriteTo" : [ {
68
+ " Name": " LiterateConsole" ,
69
+ " Args" : {
70
+ " outputTemplate": " {Message}"
71
+ }
70
72
}]
71
73
}
72
74
""" ;
@@ -88,28 +90,29 @@ public void WriteToSupportExpandedSyntaxWithArgs()
88
90
[ Fact ]
89
91
public void WriteToSupportMultipleSinksOfTheSameKind ( )
90
92
{
93
+ // language=json
91
94
var json = """
92
95
{
93
- ' WriteTo' : [
96
+ " WriteTo" : [
94
97
{
95
- ' Name': ' LiterateConsole' ,
96
- ' Args' : {
97
- ' outputTemplate': ' {Message}'
98
- },
98
+ " Name": " LiterateConsole" ,
99
+ " Args" : {
100
+ " outputTemplate": " {Message}"
101
+ }
99
102
},
100
- ' DiagnosticTrace'
103
+ " DiagnosticTrace"
101
104
],
102
- ' WriteTo:File1' : {
103
- ' Name': ' File' ,
104
- ' Args' : {
105
- ' outputTemplate': ' {Message}'
106
- },
105
+ " WriteTo:File1" : {
106
+ " Name": " File" ,
107
+ " Args" : {
108
+ " outputTemplate": " {Message}"
109
+ }
107
110
},
108
- ' WriteTo:File2' : {
109
- ' Name': ' File' ,
110
- ' Args' : {
111
- ' outputTemplate': ' {Message}'
112
- },
111
+ " WriteTo:File2" : {
112
+ " Name": " File" ,
113
+ " Args" : {
114
+ " outputTemplate": " {Message}"
115
+ }
113
116
}
114
117
}
115
118
""" ;
@@ -129,9 +132,10 @@ public void WriteToSupportMultipleSinksOfTheSameKind()
129
132
[ Fact ]
130
133
public void Enrich_SupportSimplifiedSyntax ( )
131
134
{
135
+ // language=json
132
136
var json = """
133
137
{
134
- ' Enrich' : [ ' FromLogContext', ' WithMachineName', ' WithThreadId' ]
138
+ " Enrich" : [ " FromLogContext", " WithMachineName", " WithThreadId" ]
135
139
}
136
140
""" ;
137
141
@@ -274,7 +278,18 @@ public void MixedMinimumLevelCorrectOneIsEnabledOnLogger(IConfigurationRoot root
274
278
[ Fact ]
275
279
public void NoConfigurationRootUsedStillValid ( )
276
280
{
277
- var section = JsonStringConfigSource . LoadSection ( "{ 'Nest': { 'Serilog': { 'MinimumLevel': 'Error' } } }" , "Nest" ) ;
281
+ // language=json
282
+ var json = """
283
+ {
284
+ "Nest": {
285
+ "Serilog": {
286
+ "MinimumLevel": "Error"
287
+ }
288
+ }
289
+ }
290
+ """ ;
291
+
292
+ var section = JsonStringConfigSource . LoadSection ( json , "Nest" ) ;
278
293
var reader = new ConfigurationReader ( section . GetSection ( "Serilog" ) , AssemblyFinder . ForSource ( ConfigurationAssemblySource . UseLoadedAssemblies ) , new ConfigurationReaderOptions ( ) , section ) ;
279
294
var loggerConfig = new LoggerConfiguration ( ) ;
280
295
0 commit comments