diff --git a/test/Serilog.Settings.Configuration.Tests/ConfigurationReaderTests.cs b/test/Serilog.Settings.Configuration.Tests/ConfigurationReaderTests.cs index 4658f70..2c91abf 100644 --- a/test/Serilog.Settings.Configuration.Tests/ConfigurationReaderTests.cs +++ b/test/Serilog.Settings.Configuration.Tests/ConfigurationReaderTests.cs @@ -16,7 +16,7 @@ public class ConfigurationReaderTests public ConfigurationReaderTests() { _configurationReader = new ConfigurationReader( - JsonStringConfigSource.LoadSection(@"{ 'Serilog': { } }", "Serilog"), + JsonStringConfigSource.LoadSection("{ 'Serilog': { } }", "Serilog"), AssemblyFinder.ForSource(ConfigurationAssemblySource.UseLoadedAssemblies), CultureInfo.InvariantCulture); } @@ -24,10 +24,11 @@ public ConfigurationReaderTests() [Fact] public void WriteToSupportSimplifiedSyntax() { - var json = @" -{ - 'WriteTo': [ 'LiterateConsole', 'DiagnosticTrace' ] -}"; + var json = """ + { + 'WriteTo': [ 'LiterateConsole', 'DiagnosticTrace' ] + } + """; var result = _configurationReader.GetMethodCalls(JsonStringConfigSource.LoadSection(json, "WriteTo")); Assert.Equal(2, result.Count); @@ -41,12 +42,13 @@ public void WriteToSupportSimplifiedSyntax() [Fact] public void WriteToSupportExpandedSyntaxWithoutArgs() { - var json = @" -{ - 'WriteTo': [ { - 'Name': 'LiterateConsole' - }] -}"; + var json = """ + { + 'WriteTo': [ { + 'Name': 'LiterateConsole' + }] + } + """; var result = _configurationReader.GetMethodCalls(JsonStringConfigSource.LoadSection(json, "WriteTo")); Assert.Equal(1, result.Count); @@ -58,15 +60,16 @@ public void WriteToSupportExpandedSyntaxWithoutArgs() [Fact] public void WriteToSupportExpandedSyntaxWithArgs() { - var json = @" -{ - 'WriteTo': [ { - 'Name': 'LiterateConsole', - 'Args': { - 'outputTemplate': '{Message}' - }, - }] -}"; + var json = """ + { + 'WriteTo': [ { + 'Name': 'LiterateConsole', + 'Args': { + 'outputTemplate': '{Message}' + }, + }] + } + """; var result = _configurationReader.GetMethodCalls(JsonStringConfigSource.LoadSection(json, "WriteTo")); @@ -85,30 +88,31 @@ public void WriteToSupportExpandedSyntaxWithArgs() [Fact] public void WriteToSupportMultipleSinksOfTheSameKind() { - var json = @" -{ - 'WriteTo': [ - { - 'Name': 'LiterateConsole', - 'Args': { - 'outputTemplate': '{Message}' - }, - }, - 'DiagnosticTrace' - ], - 'WriteTo:File1': { - 'Name': 'File', - 'Args': { - 'outputTemplate': '{Message}' - }, - }, - 'WriteTo:File2': { - 'Name': 'File', - 'Args': { - 'outputTemplate': '{Message}' - }, - } -}"; + var json = """ + { + 'WriteTo': [ + { + 'Name': 'LiterateConsole', + 'Args': { + 'outputTemplate': '{Message}' + }, + }, + 'DiagnosticTrace' + ], + 'WriteTo:File1': { + 'Name': 'File', + 'Args': { + 'outputTemplate': '{Message}' + }, + }, + 'WriteTo:File2': { + 'Name': 'File', + 'Args': { + 'outputTemplate': '{Message}' + }, + } + } + """; var result = _configurationReader.GetMethodCalls(JsonStringConfigSource.LoadSection(json, "WriteTo")); @@ -125,10 +129,11 @@ public void WriteToSupportMultipleSinksOfTheSameKind() [Fact] public void Enrich_SupportSimplifiedSyntax() { - var json = @" -{ - 'Enrich': [ 'FromLogContext', 'WithMachineName', 'WithThreadId' ] -}"; + var json = """ + { + 'Enrich': [ 'FromLogContext', 'WithMachineName', 'WithThreadId' ] + } + """; var result = _configurationReader.GetMethodCalls(JsonStringConfigSource.LoadSection(json, "Enrich")); Assert.Equal(3, result.Count); @@ -269,7 +274,7 @@ public void MixedMinimumLevelCorrectOneIsEnabledOnLogger(IConfigurationRoot root [Fact] public void NoConfigurationRootUsedStillValid() { - var section = JsonStringConfigSource.LoadSection(@"{ 'Nest': { 'Serilog': { 'MinimumLevel': 'Error' } } }", "Nest"); + var section = JsonStringConfigSource.LoadSection("{ 'Nest': { 'Serilog': { 'MinimumLevel': 'Error' } } }", "Nest"); var reader = new ConfigurationReader(section.GetSection("Serilog"), AssemblyFinder.ForSource(ConfigurationAssemblySource.UseLoadedAssemblies), CultureInfo.InvariantCulture, section); var loggerConfig = new LoggerConfiguration(); diff --git a/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs b/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs index 9689c05..9d82348 100644 --- a/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs +++ b/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs @@ -36,13 +36,15 @@ public void PropertyEnrichmentIsApplied() { LogEvent evt = null; - var json = @"{ - ""Serilog"": { - ""Properties"": { - ""App"": ""Test"" + var json = """ + { + "Serilog": { + "Properties": { + "App": "Test" } } - }"; + } + """; var log = ConfigFromJson(json) .WriteTo.Sink(new DelegatingSink(e => evt = e)) @@ -55,23 +57,25 @@ public void PropertyEnrichmentIsApplied() } [Theory] - [InlineData("extended syntax", - @"{ - ""Serilog"": { - ""Using"": [""TestDummies""], - ""WriteTo"": [ - { ""Name"": ""DummyConsole""}, - { ""Name"": ""DummyWithLevelSwitch""}, - ] - } - }")] - [InlineData("simplified syntax", - @"{ - ""Serilog"": { - ""Using"": [""TestDummies""], - ""WriteTo"": [""DummyConsole"", ""DummyWithLevelSwitch"" ] - } - }")] + [InlineData("extended syntax", """ + { + "Serilog": { + "Using": ["TestDummies"], + "WriteTo": [ + { "Name": "DummyConsole"}, + { "Name": "DummyWithLevelSwitch"}, + ] + } + } + """)] + [InlineData("simplified syntax", """ + { + "Serilog": { + "Using": ["TestDummies"], + "WriteTo": ["DummyConsole", "DummyWithLevelSwitch" ] + } + } + """)] public void ParameterlessSinksAreConfigured(string syntax, string json) { _ = syntax; @@ -91,12 +95,14 @@ public void ParameterlessSinksAreConfigured(string syntax, string json) [Fact] public void ConfigurationAssembliesFromDllScanning() { - var json = @"{ - ""Serilog"": { - ""Using"": [""TestDummies""], - ""WriteTo"": [""DummyConsole""] + var json = """ + { + "Serilog": { + "Using": ["TestDummies"], + "WriteTo": ["DummyConsole"] } - }"; + } + """; var builder = new ConfigurationBuilder().AddJsonString(json); var config = builder.Build(); @@ -116,15 +122,17 @@ public void ConfigurationAssembliesFromDllScanning() [Fact] public void SinksAreConfigured() { - var json = @"{ - ""Serilog"": { - ""Using"": [""TestDummies""], - ""WriteTo"": [{ - ""Name"": ""DummyRollingFile"", - ""Args"": {""pathFormat"" : ""C:\\""} + var json = """ + { + "Serilog": { + "Using": ["TestDummies"], + "WriteTo": [{ + "Name": "DummyRollingFile", + "Args": {"pathFormat" : "C:\\"} }] } - }"; + } + """; var log = ConfigFromJson(json) .CreateLogger(); @@ -141,15 +149,17 @@ public void SinksAreConfigured() [Fact] public void AuditSinksAreConfigured() { - var json = @"{ - ""Serilog"": { - ""Using"": [""TestDummies""], - ""AuditTo"": [{ - ""Name"": ""DummyRollingFile"", - ""Args"": {""pathFormat"" : ""C:\\""} + var json = """ + { + "Serilog": { + "Using": ["TestDummies"], + "AuditTo": [{ + "Name": "DummyRollingFile", + "Args": {"pathFormat" : "C:\\"} }] } - }"; + } + """; var log = ConfigFromJson(json) .CreateLogger(); @@ -166,21 +176,23 @@ public void AuditSinksAreConfigured() [Fact] public void AuditToSubLoggersAreConfigured() { - var json = @"{ - ""Serilog"": { - ""Using"": [""TestDummies""], - ""AuditTo"": [{ - ""Name"": ""Logger"", - ""Args"": { - ""configureLogger"" : { - ""AuditTo"": [{ - ""Name"": ""DummyRollingFile"", - ""Args"": {""pathFormat"" : ""C:\\""} - }]} - } - }] + var json = """ + { + "Serilog": { + "Using": ["TestDummies"], + "AuditTo": [{ + "Name": "Logger", + "Args": { + "configureLogger" : { + "AuditTo": [{ + "Name": "DummyRollingFile", + "Args": {"pathFormat" : "C:\\"} + }]} + } + }] + } } - }"; + """; var log = ConfigFromJson(json) .CreateLogger(); @@ -197,15 +209,17 @@ public void AuditToSubLoggersAreConfigured() [Fact] public void TestMinimumLevelOverrides() { - var json = @"{ - ""Serilog"": { - ""MinimumLevel"" : { - ""Override"" : { - ""System"" : ""Warning"" + var json = """ + { + "Serilog": { + "MinimumLevel" : { + "Override" : { + "System" : "Warning" } } } - }"; + } + """; LogEvent evt = null; @@ -229,17 +243,19 @@ public void TestMinimumLevelOverrides() [Fact] public void TestMinimumLevelOverridesForChildContext() { - var json = @"{ - ""Serilog"": { - ""MinimumLevel"" : { - ""Default"" : ""Warning"", - ""Override"" : { - ""System"" : ""Warning"", - ""System.Threading"": ""Debug"" + var json = """ + { + "Serilog": { + "MinimumLevel" : { + "Default" : "Warning", + "Override" : { + "System" : "Warning", + "System.Threading": "Debug" } } } - }"; + } + """; LogEvent evt = null; @@ -263,15 +279,17 @@ public void TestMinimumLevelOverridesForChildContext() [Fact] public void SinksWithAbstractParamsAreConfiguredWithTypeName() { - var json = @"{ - ""Serilog"": { - ""Using"": [""TestDummies""], - ""WriteTo"": [{ - ""Name"": ""DummyConsole"", - ""Args"": {""theme"" : ""Serilog.Settings.Configuration.Tests.Support.CustomConsoleTheme, Serilog.Settings.Configuration.Tests""} + var json = """ + { + "Serilog": { + "Using": ["TestDummies"], + "WriteTo": [{ + "Name": "DummyConsole", + "Args": {"theme" : "Serilog.Settings.Configuration.Tests.Support.CustomConsoleTheme, Serilog.Settings.Configuration.Tests"} }] } - }"; + } + """; DummyConsoleSink.Theme = null; @@ -285,15 +303,17 @@ public void SinksWithAbstractParamsAreConfiguredWithTypeName() [Fact] public void SinksAreConfiguredWithStaticMember() { - var json = @"{ - ""Serilog"": { - ""Using"": [""TestDummies""], - ""WriteTo"": [{ - ""Name"": ""DummyConsole"", - ""Args"": {""theme"" : ""TestDummies.Console.Themes.ConsoleThemes::Theme1, TestDummies""} + var json = """ + { + "Serilog": { + "Using": ["TestDummies"], + "WriteTo": [{ + "Name": "DummyConsole", + "Args": {"theme" : "TestDummies.Console.Themes.ConsoleThemes::Theme1, TestDummies"} }] } - }"; + } + """; DummyConsoleSink.Theme = null; @@ -328,11 +348,13 @@ public void LoggingLevelSwitchNameValidityScenarios(string switchName, bool expe [Fact] public void LoggingLevelSwitchWithInvalidNameThrowsFormatException() { - var json = @"{ - ""Serilog"": { - ""LevelSwitches"": {""1InvalidSwitchName"" : ""Warning"" } + var json = """ + { + "Serilog": { + "LevelSwitches": {"1InvalidSwitchName" : "Warning" } } - }"; + } + """; var ex = Assert.Throws(() => ConfigFromJson(json)); @@ -346,17 +368,19 @@ public void LoggingLevelSwitchWithInvalidNameThrowsFormatException() [InlineData("mySwitch")] public void LoggingFilterSwitchIsConfigured(string switchName) { - var json = $@"{{ - 'Serilog': {{ - 'FilterSwitches': {{ '{switchName}': 'Prop = 42' }}, - 'Filter:BySwitch': {{ + var json = $$""" + { + 'Serilog': { + 'FilterSwitches': { '{{switchName}}': 'Prop = 42' }, + 'Filter:BySwitch': { 'Name': 'ControlledBy', - 'Args': {{ + 'Args': { 'switch': '$mySwitch' - }} - }} - }} - }}"; + } + } + } + } + """; LogEvent evt = null; var log = ConfigFromJson(json) @@ -375,14 +399,16 @@ public void LoggingFilterSwitchIsConfigured(string switchName) [InlineData("switch1")] public void LoggingLevelSwitchIsConfigured(string switchName) { - var json = $@"{{ - 'Serilog': {{ - 'LevelSwitches': {{ '{switchName}' : 'Warning' }}, - 'MinimumLevel' : {{ + var json = $$""" + { + 'Serilog': { + 'LevelSwitches': { '{{switchName}}' : 'Warning' }, + 'MinimumLevel' : { 'ControlledBy' : '$switch1' - }} - }} - }}"; + } + } + } + """; LogEvent evt = null; var log = ConfigFromJson(json) @@ -400,14 +426,16 @@ public void LoggingLevelSwitchIsConfigured(string switchName) [Fact] public void SettingMinimumLevelControlledByToAnUndeclaredSwitchThrows() { - var json = @"{ - ""Serilog"": { - ""LevelSwitches"": {""$switch1"" : ""Warning"" }, - ""MinimumLevel"" : { - ""ControlledBy"" : ""$switch2"" + var json = """ + { + "Serilog": { + "LevelSwitches": {"$switch1" : "Warning" }, + "MinimumLevel" : { + "ControlledBy" : "$switch2" } } - }"; + } + """; var ex = Assert.Throws(() => ConfigFromJson(json) @@ -420,19 +448,21 @@ public void SettingMinimumLevelControlledByToAnUndeclaredSwitchThrows() [Fact] public void LoggingLevelSwitchIsPassedToSinks() { - var json = @"{ - ""Serilog"": { - ""Using"": [""TestDummies""], - ""LevelSwitches"": {""$switch1"" : ""Information"" }, - ""MinimumLevel"" : { - ""ControlledBy"" : ""$switch1"" + var json = """ + { + "Serilog": { + "Using": ["TestDummies"], + "LevelSwitches": {"$switch1" : "Information" }, + "MinimumLevel" : { + "ControlledBy" : "$switch1" }, - ""WriteTo"": [{ - ""Name"": ""DummyWithLevelSwitch"", - ""Args"": {""controlLevelSwitch"" : ""$switch1""} + "WriteTo": [{ + "Name": "DummyWithLevelSwitch", + "Args": {"controlLevelSwitch" : "$switch1"} }] } - }"; + } + """; LogEvent evt = null; @@ -456,19 +486,21 @@ public void LoggingLevelSwitchIsPassedToSinks() [Fact] public void ReferencingAnUndeclaredSwitchInSinkThrows() { - var json = @"{ - ""Serilog"": { - ""Using"": [""TestDummies""], - ""LevelSwitches"": {""$switch1"" : ""Information"" }, - ""MinimumLevel"" : { - ""ControlledBy"" : ""$switch1"" + var json = """ + { + "Serilog": { + "Using": ["TestDummies"], + "LevelSwitches": {"$switch1" : "Information" }, + "MinimumLevel" : { + "ControlledBy" : "$switch1" }, - ""WriteTo"": [{ - ""Name"": ""DummyWithLevelSwitch"", - ""Args"": {""controlLevelSwitch"" : ""$switch2""} + "WriteTo": [{ + "Name": "DummyWithLevelSwitch", + "Args": {"controlLevelSwitch" : "$switch2"} }] } - }"; + } + """; var ex = Assert.Throws(() => ConfigFromJson(json) @@ -481,22 +513,24 @@ public void ReferencingAnUndeclaredSwitchInSinkThrows() [Fact] public void LoggingLevelSwitchCanBeUsedForMinimumLevelOverrides() { - var json = @"{ - ""Serilog"": { - ""Using"": [""TestDummies""], - ""LevelSwitches"": {""$specificSwitch"" : ""Warning"" }, - ""MinimumLevel"" : { - ""Default"" : ""Debug"", - ""Override"" : { - ""System"" : ""$specificSwitch"" + var json = """ + { + "Serilog": { + "Using": ["TestDummies"], + "LevelSwitches": {"$specificSwitch" : "Warning" }, + "MinimumLevel" : { + "Default" : "Debug", + "Override" : { + "System" : "$specificSwitch" } }, - ""WriteTo"": [{ - ""Name"": ""DummyWithLevelSwitch"", - ""Args"": {""controlLevelSwitch"" : ""$specificSwitch""} + "WriteTo": [{ + "Name": "DummyWithLevelSwitch", + "Args": {"controlLevelSwitch" : "$specificSwitch"} }] } - }"; + } + """; LogEvent evt = null; @@ -532,15 +566,17 @@ public void LoggingLevelSwitchCanBeUsedForMinimumLevelOverrides() [Trait("BugFix", "https://github.com/serilog/serilog-settings-configuration/issues/142")] public void SinkWithIConfigurationArguments() { - var json = @"{ - ""Serilog"": { - ""Using"": [""TestDummies""], - ""WriteTo"": [{ - ""Name"": ""DummyWithConfiguration"", - ""Args"": {} + var json = """ + { + "Serilog": { + "Using": ["TestDummies"], + "WriteTo": [{ + "Name": "DummyWithConfiguration", + "Args": {} }] } - }"; + } + """; DummyConfigurationSink.Reset(); var log = ConfigFromJson(json, out var expectedConfig) @@ -556,15 +592,17 @@ public void SinkWithIConfigurationArguments() [Trait("BugFix", "https://github.com/serilog/serilog-settings-configuration/issues/142")] public void SinkWithOptionalIConfigurationArguments() { - var json = @"{ - ""Serilog"": { - ""Using"": [""TestDummies""], - ""WriteTo"": [{ - ""Name"": ""DummyWithOptionalConfiguration"", - ""Args"": {} + var json = """ + { + "Serilog": { + "Using": ["TestDummies"], + "WriteTo": [{ + "Name": "DummyWithOptionalConfiguration", + "Args": {} }] } - }"; + } + """; DummyConfigurationSink.Reset(); var log = ConfigFromJson(json, out var expectedConfig) @@ -580,15 +618,17 @@ public void SinkWithOptionalIConfigurationArguments() [Fact] public void SinkWithIConfigSectionArguments() { - var json = @"{ - ""Serilog"": { - ""Using"": [""TestDummies""], - ""WriteTo"": [{ - ""Name"": ""DummyWithConfigSection"", - ""Args"": {""configurationSection"" : { ""foo"" : ""bar"" } } + var json = """ + { + "Serilog": { + "Using": ["TestDummies"], + "WriteTo": [{ + "Name": "DummyWithConfigSection", + "Args": {"configurationSection" : { "foo" : "bar" } } }] } - }"; + } + """; DummyConfigurationSink.Reset(); var log = ConfigFromJson(json) @@ -604,16 +644,18 @@ public void SinkWithIConfigSectionArguments() [Fact] public void SinkWithConfigurationBindingArgument() { - var json = @"{ - ""Serilog"": { - ""Using"": [""TestDummies""], - ""WriteTo"": [{ - ""Name"": ""DummyRollingFile"", - ""Args"": {""pathFormat"" : ""C:\\"", - ""objectBinding"" : [ { ""foo"" : ""bar"" }, { ""abc"" : ""xyz"" } ] } + var json = """ + { + "Serilog": { + "Using": ["TestDummies"], + "WriteTo": [{ + "Name": "DummyRollingFile", + "Args": {"pathFormat" : "C:\\", + "objectBinding" : [ { "foo" : "bar" }, { "abc" : "xyz" } ] } }] } - }"; + } + """; var log = ConfigFromJson(json) .CreateLogger(); @@ -628,16 +670,18 @@ public void SinkWithConfigurationBindingArgument() [Fact] public void SinkWithStringArrayArgument() { - var json = @"{ - ""Serilog"": { - ""Using"": [""TestDummies""], - ""WriteTo"": [{ - ""Name"": ""DummyRollingFile"", - ""Args"": {""pathFormat"" : ""C:\\"", - ""stringArrayBinding"" : [ ""foo"", ""bar"", ""baz"" ] } + var json = """ + { + "Serilog": { + "Using": ["TestDummies"], + "WriteTo": [{ + "Name": "DummyRollingFile", + "Args": {"pathFormat" : "C:\\", + "stringArrayBinding" : [ "foo", "bar", "baz" ] } }] } - }"; + } + """; var log = ConfigFromJson(json) .CreateLogger(); @@ -664,19 +708,21 @@ public void DestructureNumericNumbers(string numberDecimalSeparator) try { - var json = @"{ - ""Serilog"": { - ""Using"": [ ""TestDummies"" ], - ""Destructure"": [{ - ""Name"": ""DummyNumbers"", - ""Args"": { - ""floatValue"": 0.1, - ""doubleValue"": 0.2, - ""decimalValue"": 0.3 + var json = """ + { + "Serilog": { + "Using": [ "TestDummies" ], + "Destructure": [{ + "Name": "DummyNumbers", + "Args": { + "floatValue": 0.1, + "doubleValue": 0.2, + "decimalValue": 0.3 } }] } - }"; + } + """; DummyPolicy.Current = null; @@ -696,31 +742,33 @@ public void DestructureNumericNumbers(string numberDecimalSeparator) [Fact] public void DestructureWithCollectionsOfTypeArgument() { - var json = @"{ - ""Serilog"": { - ""Using"": [ ""TestDummies"" ], - ""Destructure"": [{ - ""Name"": ""DummyArrayOfType"", - ""Args"": { - ""list"": [ - ""System.Byte"", - ""System.Int16"" + var json = """ + { + "Serilog": { + "Using": [ "TestDummies" ], + "Destructure": [{ + "Name": "DummyArrayOfType", + "Args": { + "list": [ + "System.Byte", + "System.Int16" ], - ""array"" : [ - ""System.Int32"", - ""System.String"" + "array" : [ + "System.Int32", + "System.String" ], - ""type"" : ""System.TimeSpan"", - ""custom"" : [ - ""System.Int64"" + "type" : "System.TimeSpan", + "custom" : [ + "System.Int64" ], - ""customString"" : [ - ""System.UInt32"" + "customString" : [ + "System.UInt32" ] } }] } - }"; + } + """; DummyPolicy.Current = null; @@ -737,16 +785,18 @@ public void DestructureWithCollectionsOfTypeArgument() [Fact] public void SinkWithIntArrayArgument() { - var json = @"{ - ""Serilog"": { - ""Using"": [""TestDummies""], - ""WriteTo"": [{ - ""Name"": ""DummyRollingFile"", - ""Args"": {""pathFormat"" : ""C:\\"", - ""intArrayBinding"" : [ 1,2,3,4,5 ] } + var json = """ + { + "Serilog": { + "Using": ["TestDummies"], + "WriteTo": [{ + "Name": "DummyRollingFile", + "Args": {"pathFormat" : "C:\\", + "intArrayBinding" : [ 1,2,3,4,5 ] } }] } - }"; + } + """; var log = ConfigFromJson(json) .CreateLogger(); @@ -762,15 +812,17 @@ public void SinkWithIntArrayArgument() [Fact] public void CaseInsensitiveArgumentNameMatching() { - var json = @"{ - ""Serilog"": { - ""Using"": [""TestDummies""], - ""WriteTo"": [{ - ""Name"": ""DummyRollingFile"", - ""Args"": {""PATHFORMAT"" : ""C:\\""} + var json = """ + { + "Serilog": { + "Using": ["TestDummies"], + "WriteTo": [{ + "Name": "DummyRollingFile", + "Args": {"PATHFORMAT" : "C:\\"} }] } - }"; + } + """; var log = ConfigFromJson(json) .CreateLogger(); @@ -786,22 +838,24 @@ public void CaseInsensitiveArgumentNameMatching() [Fact] public void WriteToLoggerWithRestrictedToMinimumLevelIsSupported() { - var json = @"{ - ""Serilog"": { - ""Using"": [""TestDummies""], - ""WriteTo"": [{ - ""Name"": ""Logger"", - ""Args"": { - ""configureLogger"" : { - ""WriteTo"": [{ - ""Name"": ""DummyRollingFile"", - ""Args"": {""pathFormat"" : ""C:\\""} + var json = """ + { + "Serilog": { + "Using": ["TestDummies"], + "WriteTo": [{ + "Name": "Logger", + "Args": { + "configureLogger" : { + "WriteTo": [{ + "Name": "DummyRollingFile", + "Args": {"pathFormat" : "C:\\"} }]}, - ""restrictedToMinimumLevel"": ""Warning"" + "restrictedToMinimumLevel": "Warning" } }] } - }"; + } + """; var log = ConfigFromJson(json) .CreateLogger(); @@ -818,25 +872,27 @@ public void WriteToLoggerWithRestrictedToMinimumLevelIsSupported() [Fact] public void WriteToSubLoggerWithLevelSwitchIsSupported() { - var json = @"{ - ""Serilog"": { - ""Using"": [""TestDummies""], - ""LevelSwitches"": {""$switch1"" : ""Warning"" }, - ""MinimumLevel"" : { - ""ControlledBy"" : ""$switch1"" + var json = """ + { + "Serilog": { + "Using": ["TestDummies"], + "LevelSwitches": {"$switch1" : "Warning" }, + "MinimumLevel" : { + "ControlledBy" : "$switch1" }, - ""WriteTo"": [{ - ""Name"": ""Logger"", - ""Args"": { - ""configureLogger"" : { - ""WriteTo"": [{ - ""Name"": ""DummyRollingFile"", - ""Args"": {""pathFormat"" : ""C:\\""} + "WriteTo": [{ + "Name": "Logger", + "Args": { + "configureLogger" : { + "WriteTo": [{ + "Name": "DummyRollingFile", + "Args": {"pathFormat" : "C:\\"} }]} } }] } - }"; + } + """; var log = ConfigFromJson(json) .CreateLogger(); @@ -853,25 +909,29 @@ public void WriteToSubLoggerWithLevelSwitchIsSupported() [Fact] public void InconsistentComplexVsScalarArgumentValuesThrowsIOE() { - var jsonDiscreteValue = @"{ - ""Serilog"": { - ""Using"": [""TestDummies""], - ""WriteTo"": [{ - ""Name"": ""DummyRollingFile"", - ""Args"": {""pathFormat"" : ""C:\\""} + var jsonDiscreteValue = """ + { + "Serilog": { + "Using": ["TestDummies"], + "WriteTo": [{ + "Name": "DummyRollingFile", + "Args": {"pathFormat" : "C:\\"} }] } - }"; - - var jsonComplexValue = @"{ - ""Serilog"": { - ""Using"": [""TestDummies""], - ""WriteTo"": [{ - ""Name"": ""DummyRollingFile"", - ""Args"": {""pathFormat"" : { ""foo"" : ""bar"" } } + } + """; + + var jsonComplexValue = """ + { + "Serilog": { + "Using": ["TestDummies"], + "WriteTo": [{ + "Name": "DummyRollingFile", + "Args": {"pathFormat" : { "foo" : "bar" } } }] } - }"; + } + """; // These will combine into a ConfigurationSection object that has both // Value == "C:\" and GetChildren() == List. No configuration @@ -890,15 +950,17 @@ public void InconsistentComplexVsScalarArgumentValuesThrowsIOE() [Fact] public void DestructureLimitsNestingDepth() { - var json = @"{ - ""Serilog"": { - ""Destructure"": [ + var json = """ + { + "Serilog": { + "Destructure": [ { - ""Name"": ""ToMaximumDepth"", - ""Args"": { ""maximumDestructuringDepth"": 3 } + "Name": "ToMaximumDepth", + "Args": { "maximumDestructuringDepth": 3 } }] } - }"; + } + """; var NestedObject = new { @@ -923,15 +985,17 @@ public void DestructureLimitsNestingDepth() [Fact] public void DestructureLimitsStringLength() { - var json = @"{ - ""Serilog"": { - ""Destructure"": [ + var json = """ + { + "Serilog": { + "Destructure": [ { - ""Name"": ""ToMaximumStringLength"", - ""Args"": { ""maximumStringLength"": 3 } + "Name": "ToMaximumStringLength", + "Args": { "maximumStringLength": 3 } }] } - }"; + } + """; var inputString = "ABCDEFGH"; var msg = GetDestructuredProperty(inputString, json); @@ -942,15 +1006,17 @@ public void DestructureLimitsStringLength() [Fact] public void DestructureLimitsCollectionCount() { - var json = @"{ - ""Serilog"": { - ""Destructure"": [ + var json = """ + { + "Serilog": { + "Destructure": [ { - ""Name"": ""ToMaximumCollectionCount"", - ""Args"": { ""maximumCollectionCount"": 3 } + "Name": "ToMaximumCollectionCount", + "Args": { "maximumCollectionCount": 3 } }] } - }"; + } + """; var collection = new[] { 1, 2, 3, 4, 5, 6 }; var msg = GetDestructuredProperty(collection, json); @@ -973,16 +1039,18 @@ private static string GetDestructuredProperty(object x, string json) [Fact] public void DestructuringWithCustomExtensionMethodIsApplied() { - var json = @"{ - ""Serilog"": { - ""Using"": [""TestDummies""], - ""Destructure"": [ + var json = """ + { + "Serilog": { + "Using": ["TestDummies"], + "Destructure": [ { - ""Name"": ""WithDummyHardCodedString"", - ""Args"": { ""hardCodedString"": ""hardcoded"" } + "Name": "WithDummyHardCodedString", + "Args": { "hardCodedString": "hardcoded" } }] } - }"; + } + """; LogEvent evt = null; var log = ConfigFromJson(json) @@ -997,15 +1065,17 @@ public void DestructuringWithCustomExtensionMethodIsApplied() [Fact] public void DestructuringAsScalarIsAppliedWithShortTypeName() { - var json = @"{ - ""Serilog"": { - ""Destructure"": [ + var json = """ + { + "Serilog": { + "Destructure": [ { - ""Name"": ""AsScalar"", - ""Args"": { ""scalarType"": ""System.Version"" } + "Name": "AsScalar", + "Args": { "scalarType": "System.Version" } }] } - }"; + } + """; LogEvent evt = null; var log = ConfigFromJson(json) @@ -1021,15 +1091,17 @@ public void DestructuringAsScalarIsAppliedWithShortTypeName() [Fact] public void DestructuringAsScalarIsAppliedWithAssemblyQualifiedName() { - var json = $@"{{ - ""Serilog"": {{ - ""Destructure"": [ - {{ - ""Name"": ""AsScalar"", - ""Args"": {{ ""scalarType"": ""{typeof(Version).AssemblyQualifiedName}"" }} - }}] - }} - }}"; + var json = $$""" + { + "Serilog": { + "Destructure": [ + { + "Name": "AsScalar", + "Args": { "scalarType": "{{typeof(Version).AssemblyQualifiedName}}" } + }] + } + } + """; LogEvent evt = null; var log = ConfigFromJson(json) @@ -1045,18 +1117,20 @@ public void DestructuringAsScalarIsAppliedWithAssemblyQualifiedName() [Fact] public void WriteToSinkIsAppliedWithCustomSink() { - var json = $@"{{ - ""Serilog"": {{ - ""Using"": [""TestDummies""], - ""WriteTo"": [ - {{ - ""Name"": ""Sink"", - ""Args"": {{ - ""sink"": ""{typeof(DummyRollingFileSink).AssemblyQualifiedName}"" - }} - }}] - }} - }}"; + var json = $$""" + { + "Serilog": { + "Using": ["TestDummies"], + "WriteTo": [ + { + "Name": "Sink", + "Args": { + "sink": "{{typeof(DummyRollingFileSink).AssemblyQualifiedName}}" + } + }] + } + } + """; var log = ConfigFromJson(json) .CreateLogger(); @@ -1070,19 +1144,21 @@ public void WriteToSinkIsAppliedWithCustomSink() [Fact] public void WriteToSinkIsAppliedWithCustomSinkAndMinimumLevel() { - var json = $@"{{ - ""Serilog"": {{ - ""Using"": [""TestDummies""], - ""WriteTo"": [ - {{ - ""Name"": ""Sink"", - ""Args"": {{ - ""sink"": ""{typeof(DummyRollingFileSink).AssemblyQualifiedName}"", - ""restrictedToMinimumLevel"": ""Warning"" - }} - }}] - }} - }}"; + var json = $$""" + { + "Serilog": { + "Using": ["TestDummies"], + "WriteTo": [ + { + "Name": "Sink", + "Args": { + "sink": "{{typeof(DummyRollingFileSink).AssemblyQualifiedName}}", + "restrictedToMinimumLevel": "Warning" + } + }] + } + } + """; var log = ConfigFromJson(json) .CreateLogger(); @@ -1097,20 +1173,22 @@ public void WriteToSinkIsAppliedWithCustomSinkAndMinimumLevel() [Fact] public void WriteToSinkIsAppliedWithCustomSinkAndLevelSwitch() { - var json = $@"{{ - ""Serilog"": {{ - ""Using"": [""TestDummies""], - ""LevelSwitches"": {{""$switch1"": ""Warning"" }}, - ""WriteTo"": [ - {{ - ""Name"": ""Sink"", - ""Args"": {{ - ""sink"": ""{typeof(DummyRollingFileSink).AssemblyQualifiedName}"", - ""levelSwitch"": ""$switch1"" - }} - }}] - }} - }}"; + var json = $$""" + { + "Serilog": { + "Using": ["TestDummies"], + "LevelSwitches": {"$switch1": "Warning" }, + "WriteTo": [ + { + "Name": "Sink", + "Args": { + "sink": "{{typeof(DummyRollingFileSink).AssemblyQualifiedName}}", + "levelSwitch": "$switch1" + } + }] + } + } + """; var log = ConfigFromJson(json) .CreateLogger(); @@ -1125,18 +1203,20 @@ public void WriteToSinkIsAppliedWithCustomSinkAndLevelSwitch() [Fact] public void AuditToSinkIsAppliedWithCustomSink() { - var json = $@"{{ - ""Serilog"": {{ - ""Using"": [""TestDummies""], - ""AuditTo"": [ - {{ - ""Name"": ""Sink"", - ""Args"": {{ - ""sink"": ""{typeof(DummyRollingFileSink).AssemblyQualifiedName}"" - }} - }}] - }} - }}"; + var json = $$""" + { + "Serilog": { + "Using": ["TestDummies"], + "AuditTo": [ + { + "Name": "Sink", + "Args": { + "sink": "{{typeof(DummyRollingFileSink).AssemblyQualifiedName}}" + } + }] + } + } + """; var log = ConfigFromJson(json) .CreateLogger(); @@ -1150,19 +1230,21 @@ public void AuditToSinkIsAppliedWithCustomSink() [Fact] public void AuditToSinkIsAppliedWithCustomSinkAndMinimumLevel() { - var json = $@"{{ - ""Serilog"": {{ - ""Using"": [""TestDummies""], - ""AuditTo"": [ - {{ - ""Name"": ""Sink"", - ""Args"": {{ - ""sink"": ""{typeof(DummyRollingFileSink).AssemblyQualifiedName}"", - ""restrictedToMinimumLevel"": ""Warning"" - }} - }}] - }} - }}"; + var json = $$""" + { + "Serilog": { + "Using": ["TestDummies"], + "AuditTo": [ + { + "Name": "Sink", + "Args": { + "sink": "{{typeof(DummyRollingFileSink).AssemblyQualifiedName}}", + "restrictedToMinimumLevel": "Warning" + } + }] + } + } + """; var log = ConfigFromJson(json) .CreateLogger(); @@ -1177,20 +1259,22 @@ public void AuditToSinkIsAppliedWithCustomSinkAndMinimumLevel() [Fact] public void AuditToSinkIsAppliedWithCustomSinkAndLevelSwitch() { - var json = $@"{{ - ""Serilog"": {{ - ""Using"": [""TestDummies""], - ""LevelSwitches"": {{""$switch1"": ""Warning"" }}, - ""AuditTo"": [ - {{ - ""Name"": ""Sink"", - ""Args"": {{ - ""sink"": ""{typeof(DummyRollingFileSink).AssemblyQualifiedName}"", - ""levelSwitch"": ""$switch1"" - }} - }}] - }} - }}"; + var json = $$""" + { + "Serilog": { + "Using": ["TestDummies"], + "LevelSwitches": {"$switch1": "Warning" }, + "AuditTo": [ + { + "Name": "Sink", + "Args": { + "sink": "{{typeof(DummyRollingFileSink).AssemblyQualifiedName}}", + "levelSwitch": "$switch1" + } + }] + } + } + """; var log = ConfigFromJson(json) .CreateLogger(); @@ -1207,18 +1291,20 @@ public void EnrichWithIsAppliedWithCustomEnricher() { LogEvent evt = null; - var json = $@"{{ - ""Serilog"": {{ - ""Using"": [""TestDummies""], - ""Enrich"": [ - {{ - ""Name"": ""With"", - ""Args"": {{ - ""enricher"": ""{typeof(DummyThreadIdEnricher).AssemblyQualifiedName}"" - }} - }}] - }} - }}"; + var json = $$""" + { + "Serilog": { + "Using": ["TestDummies"], + "Enrich": [ + { + "Name": "With", + "Args": { + "enricher": "{{typeof(DummyThreadIdEnricher).AssemblyQualifiedName}}" + } + }] + } + } + """; var log = ConfigFromJson(json) .WriteTo.Sink(new DelegatingSink(e => evt = e)) @@ -1235,18 +1321,20 @@ public void FilterWithIsAppliedWithCustomFilter() { LogEvent evt = null; - var json = $@"{{ - ""Serilog"": {{ - ""Using"": [""TestDummies""], - ""Filter"": [ - {{ - ""Name"": ""With"", - ""Args"": {{ - ""filter"": ""{typeof(DummyAnonymousUserFilter).AssemblyQualifiedName}"" - }} - }}] - }} - }}"; + var json = $$""" + { + "Serilog": { + "Using": ["TestDummies"], + "Filter": [ + { + "Name": "With", + "Args": { + "filter": "{{typeof(DummyAnonymousUserFilter).AssemblyQualifiedName}}" + } + }] + } + } + """; var log = ConfigFromJson(json) .WriteTo.Sink(new DelegatingSink(e => evt = e)) diff --git a/test/Serilog.Settings.Configuration.Tests/DynamicLevelChangeTests.cs b/test/Serilog.Settings.Configuration.Tests/DynamicLevelChangeTests.cs index 1c3eb5a..f3c0b90 100644 --- a/test/Serilog.Settings.Configuration.Tests/DynamicLevelChangeTests.cs +++ b/test/Serilog.Settings.Configuration.Tests/DynamicLevelChangeTests.cs @@ -9,7 +9,8 @@ namespace Serilog.Settings.Configuration.Tests; public class DynamicLevelChangeTests { - const string DefaultConfig = @"{ + const string DefaultConfig = """ + { 'Serilog': { 'Using': [ 'TestDummies' ], 'MinimumLevel': { @@ -33,7 +34,8 @@ public class DynamicLevelChangeTests } } } - }"; + } + """; readonly ReloadableConfigurationSource _configSource; diff --git a/test/Serilog.Settings.Configuration.Tests/LoggerConfigurationExtensionsTests.cs b/test/Serilog.Settings.Configuration.Tests/LoggerConfigurationExtensionsTests.cs index 0c76cc3..c7ef68c 100644 --- a/test/Serilog.Settings.Configuration.Tests/LoggerConfigurationExtensionsTests.cs +++ b/test/Serilog.Settings.Configuration.Tests/LoggerConfigurationExtensionsTests.cs @@ -21,13 +21,15 @@ public void ReadFromConfigurationSectionReadsFromAnArbitrarySection() { LogEvent evt = null; - var json = @"{ - ""NotSerilog"": { - ""Properties"": { - ""App"": ""Test"" - } - } - }"; + var json = """ + { + "NotSerilog": { + "Properties": { + "App": "Test" + } + } + } + """; var config = new ConfigurationBuilder() .AddJsonString(json) @@ -50,15 +52,17 @@ public void ReadFromConfigurationSectionReadsFromAnArbitrarySection() [Trait("BugFix", "https://github.com/serilog/serilog-settings-configuration/issues/143")] public void ReadFromConfigurationSectionThrowsWhenTryingToCallConfigurationMethodWithIConfigurationParam() { - var json = @"{ - ""NotSerilog"": { - ""Using"": [""TestDummies""], - ""WriteTo"": [{ - ""Name"": ""DummyWithConfiguration"", - ""Args"": {} + var json = """ + { + "NotSerilog": { + "Using": ["TestDummies"], + "WriteTo": [{ + "Name": "DummyWithConfiguration", + "Args": {} }] } - }"; + } + """; var config = new ConfigurationBuilder() .AddJsonString(json) @@ -81,15 +85,17 @@ public void ReadFromConfigurationSectionThrowsWhenTryingToCallConfigurationMetho [Fact] public void ReadFromConfigurationDoesNotThrowWhenTryingToCallConfigurationMethodWithIConfigurationParam() { - var json = @"{ - ""NotSerilog"": { - ""Using"": [""TestDummies""], - ""WriteTo"": [{ - ""Name"": ""DummyWithConfiguration"", - ""Args"": {} + var json = """ + { + "NotSerilog": { + "Using": ["TestDummies"], + "WriteTo": [{ + "Name": "DummyWithConfiguration", + "Args": {} }] } - }"; + } + """; var config = new ConfigurationBuilder() .AddJsonString(json) @@ -105,15 +111,17 @@ public void ReadFromConfigurationDoesNotThrowWhenTryingToCallConfigurationMethod [Trait("BugFix", "https://github.com/serilog/serilog-settings-configuration/issues/143")] public void ReadFromConfigurationSectionDoesNotThrowWhenTryingToCallConfigurationMethodWithOptionalIConfigurationParam() { - var json = @"{ - ""NotSerilog"": { - ""Using"": [""TestDummies""], - ""WriteTo"": [{ - ""Name"": ""DummyWithOptionalConfiguration"", - ""Args"": {} + var json = """ + { + "NotSerilog": { + "Using": ["TestDummies"], + "WriteTo": [{ + "Name": "DummyWithOptionalConfiguration", + "Args": {} }] } - }"; + } + """; var config = new ConfigurationBuilder() .AddJsonString(json) diff --git a/test/Serilog.Settings.Configuration.Tests/Support/ConfigurationReaderTestHelpers.cs b/test/Serilog.Settings.Configuration.Tests/Support/ConfigurationReaderTestHelpers.cs index 4c78381..3a8c18f 100644 --- a/test/Serilog.Settings.Configuration.Tests/Support/ConfigurationReaderTestHelpers.cs +++ b/test/Serilog.Settings.Configuration.Tests/Support/ConfigurationReaderTestHelpers.cs @@ -5,20 +5,22 @@ namespace Serilog.Settings.Configuration.Tests.Support; static class ConfigurationReaderTestHelpers { - public const string minimumLevelFlatTemplate = @" -{{ - 'Serilog': {{ - 'MinimumLevel': '{0}' + public const string minimumLevelFlatTemplate = """ + {{ + 'Serilog': {{ + 'MinimumLevel': '{0}' + }} }} -}}"; - public const string minimumLevelObjectTemplate = @" -{{ - 'Serilog': {{ - 'MinimumLevel': {{ - 'Default': '{0}' + """; + public const string minimumLevelObjectTemplate = """ + {{ + 'Serilog': {{ + 'MinimumLevel': {{ + 'Default': '{0}' + }} }} }} -}}"; + """; public const string minimumLevelFlatKey = "Serilog:MinimumLevel"; public const string minimumLevelObjectKey = "Serilog:MinimumLevel:Default";