diff --git a/.gitignore b/.gitignore index 29c6d4c..318ac62 100644 --- a/.gitignore +++ b/.gitignore @@ -1,205 +1,8 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. - -# User-specific files -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -build/ -bld/ -[Bb]in/ -[Oo]bj/ - -# Visual Studo 2015 cache/options directory .vs/ - -# JetBrains project files .idea/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUNIT -*.VisualState.xml -TestResult.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -*_i.c -*_p.c -*_i.h -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opensdf -*.sdf -*.cachefile - -# Visual Studio profiler -*.psess -*.vsp -*.vspx - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# JustCode is a .NET coding addin-in -.JustCode - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# NCrunch -_NCrunch_* -.*crunch*.local.xml - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# TODO: Comment the next line if you want to checkin your web deploy settings -# but database connection strings (with potential passwords) will be unencrypted -*.pubxml -*.publishproj - -# NuGet Packages -*.nupkg -# The packages folder can be ignored because of Package Restore -**/packages/* -# except build/, which is used as an MSBuild target. -!**/packages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/packages/repositories.config - -# Windows Azure Build Output -csx/ -*.build.csdef - -# Windows Store app package directory -AppPackages/ - -# Others -*.[Cc]ache -ClientBin/ -[Ss]tyle[Cc]op.* -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.pfx -*.publishsettings -node_modules/ -bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -*.mdf -*.ldf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings - -# Microsoft Fakes -FakesAssemblies/ - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -project.lock.json - +bin/ +obj/ +test/ artifacts/ .DS_Store diff --git a/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs b/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs index bd469b3..3b86170 100644 --- a/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs +++ b/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs @@ -18,7 +18,7 @@ class ConfigurationReader : IConfigurationReader const string LevelSwitchNameRegex = @"^\${0,1}[A-Za-z]+[A-Za-z0-9]*$"; // Section names that can be handled by Serilog itself (hence builtin) without requiring any additional assemblies. - static readonly string[] BuiltinSectionNames = { "LevelSwitches", "MinimumLevel", "Properties" }; + static readonly string[] BuiltinSectionNames = ["LevelSwitches", "MinimumLevel", "Properties"]; readonly IConfiguration _section; readonly IReadOnlyCollection _configurationAssemblies; @@ -218,7 +218,7 @@ void ApplyMinimumLevelConfiguration(IConfigurationSection directive, Action FlatMinimumLevel => new List - { - new object[] { GetConfigRoot(appsettingsJsonLevel: minimumLevelFlatTemplate.Format(LogEventLevel.Error)), LogEventLevel.Error }, - new object[] { GetConfigRoot(appsettingsDevelopmentJsonLevel: minimumLevelFlatTemplate.Format(LogEventLevel.Error)), LogEventLevel.Error }, - new object[] { GetConfigRoot(envVariables: new Dictionary {{minimumLevelFlatKey, LogEventLevel.Error.ToString()}}), LogEventLevel.Error}, - new object[] { GetConfigRoot( + public static IEnumerable FlatMinimumLevel => + [ + [GetConfigRoot(appsettingsJsonLevel: minimumLevelFlatTemplate.Format(LogEventLevel.Error)), LogEventLevel.Error], + [GetConfigRoot(appsettingsDevelopmentJsonLevel: minimumLevelFlatTemplate.Format(LogEventLevel.Error)), LogEventLevel.Error], + [GetConfigRoot(envVariables: new Dictionary {{minimumLevelFlatKey, LogEventLevel.Error.ToString()}}), LogEventLevel.Error], + [GetConfigRoot( appsettingsJsonLevel: minimumLevelFlatTemplate.Format(LogEventLevel.Debug), envVariables: new Dictionary {{minimumLevelFlatKey, LogEventLevel.Error.ToString()}}), LogEventLevel.Error - } - }; + ] + ]; [Theory] [MemberData(nameof(FlatMinimumLevel))] @@ -209,17 +209,17 @@ public void FlatMinimumLevelCorrectOneIsEnabledOnLogger(IConfigurationRoot root, AssertLogEventLevels(loggerConfig, expectedMinimumLevel); } - public static IEnumerable ObjectMinimumLevel => new List - { - new object[] { GetConfigRoot(appsettingsJsonLevel: minimumLevelObjectTemplate.Format(LogEventLevel.Error)), LogEventLevel.Error }, - new object[] { GetConfigRoot(appsettingsJsonLevel: minimumLevelObjectTemplate.Format(LogEventLevel.Error.ToString().ToUpper())), LogEventLevel.Error }, - new object[] { GetConfigRoot(appsettingsDevelopmentJsonLevel: minimumLevelObjectTemplate.Format(LogEventLevel.Error)), LogEventLevel.Error }, - new object[] { GetConfigRoot(envVariables: new Dictionary{{minimumLevelObjectKey, LogEventLevel.Error.ToString() } }), LogEventLevel.Error }, - new object[] { GetConfigRoot( + public static IEnumerable ObjectMinimumLevel => + [ + [GetConfigRoot(appsettingsJsonLevel: minimumLevelObjectTemplate.Format(LogEventLevel.Error)), LogEventLevel.Error], + [GetConfigRoot(appsettingsJsonLevel: minimumLevelObjectTemplate.Format(LogEventLevel.Error.ToString().ToUpper())), LogEventLevel.Error], + [GetConfigRoot(appsettingsDevelopmentJsonLevel: minimumLevelObjectTemplate.Format(LogEventLevel.Error)), LogEventLevel.Error], + [GetConfigRoot(envVariables: new Dictionary{{minimumLevelObjectKey, LogEventLevel.Error.ToString() } }), LogEventLevel.Error], + [GetConfigRoot( appsettingsJsonLevel: minimumLevelObjectTemplate.Format(LogEventLevel.Error), appsettingsDevelopmentJsonLevel: minimumLevelObjectTemplate.Format(LogEventLevel.Debug)), - LogEventLevel.Debug } - }; + LogEventLevel.Debug ] + ]; [Theory] [MemberData(nameof(ObjectMinimumLevel))] @@ -234,25 +234,22 @@ public void ObjectMinimumLevelCorrectOneIsEnabledOnLogger(IConfigurationRoot roo } // currently only works in the .NET 4.6.1 and .NET Standard builds of Serilog.Settings.Configuration - public static IEnumerable MixedMinimumLevel => new List - { - new object[] - { + public static IEnumerable MixedMinimumLevel => + [ + [ GetConfigRoot( appsettingsJsonLevel: minimumLevelObjectTemplate.Format(LogEventLevel.Error), appsettingsDevelopmentJsonLevel: minimumLevelFlatTemplate.Format(LogEventLevel.Debug)), LogEventLevel.Debug - }, - new object[] - { + ], + [ GetConfigRoot( appsettingsJsonLevel: minimumLevelFlatTemplate.Format(LogEventLevel.Error), appsettingsDevelopmentJsonLevel: minimumLevelObjectTemplate.Format(LogEventLevel.Debug)), LogEventLevel.Debug - }, + ], // precedence should be flat > object if from the same source - new object[] - { + [ GetConfigRoot( envVariables: new Dictionary() { @@ -260,8 +257,8 @@ public void ObjectMinimumLevelCorrectOneIsEnabledOnLogger(IConfigurationRoot roo {minimumLevelFlatKey, LogEventLevel.Debug.ToString()} }), LogEventLevel.Debug - } - }; + ] + ]; [Theory] [MemberData(nameof(MixedMinimumLevel))] diff --git a/test/Serilog.Settings.Configuration.Tests/Support/ConfigurationReaderTestHelpers.cs b/test/Serilog.Settings.Configuration.Tests/Support/ConfigurationReaderTestHelpers.cs index f5e0af5..2d56813 100644 --- a/test/Serilog.Settings.Configuration.Tests/Support/ConfigurationReaderTestHelpers.cs +++ b/test/Serilog.Settings.Configuration.Tests/Support/ConfigurationReaderTestHelpers.cs @@ -55,7 +55,7 @@ public static IConfigurationRoot GetConfigRoot( configBuilder.AddJsonString(appsettingsJsonLevel ?? "{}"); configBuilder.AddJsonString(appsettingsDevelopmentJsonLevel ?? "{}"); - configBuilder.Add(new ReloadableConfigurationSource(envVariables ?? new Dictionary())); + configBuilder.Add(new ReloadableConfigurationSource(envVariables ?? [])); return configBuilder.Build(); } diff --git a/test/Serilog.Settings.Configuration.Tests/Support/TestApp.cs b/test/Serilog.Settings.Configuration.Tests/Support/TestApp.cs index 9263a66..7cf4183 100644 --- a/test/Serilog.Settings.Configuration.Tests/Support/TestApp.cs +++ b/test/Serilog.Settings.Configuration.Tests/Support/TestApp.cs @@ -26,7 +26,7 @@ public TestApp(IMessageSink messageSink) { file.CopyTo(_workingDirectory.File(file.Name).FullName, overwrite: true); } - _executables = new Dictionary(); + _executables = []; } async Task IAsyncLifetime.InitializeAsync() diff --git a/test/TestDummies/Console/DummyConsoleSink.cs b/test/TestDummies/Console/DummyConsoleSink.cs index 0486eae..5605086 100644 --- a/test/TestDummies/Console/DummyConsoleSink.cs +++ b/test/TestDummies/Console/DummyConsoleSink.cs @@ -17,7 +17,7 @@ public DummyConsoleSink(ConsoleTheme? theme = null) [ThreadStatic] static List? EmittedList; - public static List Emitted => EmittedList ??= new List(); + public static List Emitted => EmittedList ??= []; public void Emit(LogEvent logEvent) { diff --git a/test/TestDummies/DummyConfigurationSink.cs b/test/TestDummies/DummyConfigurationSink.cs index 51620ad..86b24a0 100644 --- a/test/TestDummies/DummyConfigurationSink.cs +++ b/test/TestDummies/DummyConfigurationSink.cs @@ -15,7 +15,7 @@ public class DummyConfigurationSink : ILogEventSink [ThreadStatic] static IConfigurationSection? _configSection; - public static List Emitted => _emitted ?? (_emitted = new List()); + public static List Emitted => _emitted ?? (_emitted = []); public static IConfiguration? Configuration => _configuration; diff --git a/test/TestDummies/DummyPolicy.cs b/test/TestDummies/DummyPolicy.cs index 5774510..3fe44e8 100644 --- a/test/TestDummies/DummyPolicy.cs +++ b/test/TestDummies/DummyPolicy.cs @@ -34,7 +34,7 @@ public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyV public class CustomCollection : IEnumerable { - private readonly List inner = new List(); + private readonly List inner = []; public void Add(T item) => inner.Add(item); diff --git a/test/TestDummies/DummyRollingFileAuditSink.cs b/test/TestDummies/DummyRollingFileAuditSink.cs index 3365ba5..7f94377 100644 --- a/test/TestDummies/DummyRollingFileAuditSink.cs +++ b/test/TestDummies/DummyRollingFileAuditSink.cs @@ -8,7 +8,7 @@ public class DummyRollingFileAuditSink : ILogEventSink [ThreadStatic] static List? _emitted; - public static List Emitted => _emitted ??= new List(); + public static List Emitted => _emitted ??= []; public void Emit(LogEvent logEvent) { diff --git a/test/TestDummies/DummyRollingFileSink.cs b/test/TestDummies/DummyRollingFileSink.cs index 3f8fd0e..115e075 100644 --- a/test/TestDummies/DummyRollingFileSink.cs +++ b/test/TestDummies/DummyRollingFileSink.cs @@ -8,7 +8,7 @@ public class DummyRollingFileSink : ILogEventSink [ThreadStatic] static List? _emitted; - public static List Emitted => _emitted ??= new List(); + public static List Emitted => _emitted ??= []; public void Emit(LogEvent logEvent) { diff --git a/test/TestDummies/DummyWithLevelSwitchSink.cs b/test/TestDummies/DummyWithLevelSwitchSink.cs index 2a3fadb..0d74a51 100644 --- a/test/TestDummies/DummyWithLevelSwitchSink.cs +++ b/test/TestDummies/DummyWithLevelSwitchSink.cs @@ -15,7 +15,7 @@ public DummyWithLevelSwitchSink(LoggingLevelSwitch? loggingControlLevelSwitch) [ThreadStatic] // ReSharper disable ThreadStaticFieldHasInitializer - public static List Emitted = new List(); + public static List Emitted = []; // ReSharper restore ThreadStaticFieldHasInitializer public void Emit(LogEvent logEvent) diff --git a/test/TestDummies/DummyWrappingSink.cs b/test/TestDummies/DummyWrappingSink.cs index 9dc0d35..f2188b4 100644 --- a/test/TestDummies/DummyWrappingSink.cs +++ b/test/TestDummies/DummyWrappingSink.cs @@ -8,7 +8,7 @@ public class DummyWrappingSink : ILogEventSink [ThreadStatic] static List? _emitted; - public static List Emitted => _emitted ??= new List(); + public static List Emitted => _emitted ??= []; readonly ILogEventSink _sink;