From b4ed61bd4fc66cebc61d846c8f24e0585b5f38ee Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Sun, 17 Mar 2024 20:27:49 +0300 Subject: [PATCH 1/4] Code cleanup --- .gitignore | 204 +----------------- sample/Sample/Sample.csproj | 4 +- .../Serilog.Settings.Configuration.csproj | 9 +- .../Configuration/ConfigurationReader.cs | 4 +- .../Configuration/ObjectArgumentValue.cs | 2 +- .../Configuration/ResolutionContext.cs | 2 +- .../ApiApprovalTests.cs | 4 +- .../ConfigurationReaderTests.cs | 55 +++-- ...erilog.Settings.Configuration.Tests.csproj | 10 +- .../Support/ConfigurationReaderTestHelpers.cs | 2 +- .../Support/TestApp.cs | 2 +- test/TestApp/TestApp.csproj | 2 +- test/TestDummies/Console/DummyConsoleSink.cs | 2 +- test/TestDummies/DummyConfigurationSink.cs | 2 +- test/TestDummies/DummyPolicy.cs | 2 +- test/TestDummies/DummyRollingFileAuditSink.cs | 2 +- test/TestDummies/DummyRollingFileSink.cs | 2 +- test/TestDummies/DummyWithLevelSwitchSink.cs | 2 +- test/TestDummies/DummyWrappingSink.cs | 2 +- test/TestDummies/TestDummies.csproj | 4 - 20 files changed, 54 insertions(+), 264 deletions(-) diff --git a/.gitignore b/.gitignore index c90bd95..f0d7f58 100644 --- a/.gitignore +++ b/.gitignore @@ -1,203 +1,5 @@ -## 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/ diff --git a/sample/Sample/Sample.csproj b/sample/Sample/Sample.csproj index ce3fee4..4e8277a 100644 --- a/sample/Sample/Sample.csproj +++ b/sample/Sample/Sample.csproj @@ -16,13 +16,13 @@ - + - + diff --git a/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj b/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj index 8e5a021..50bea0b 100644 --- a/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj +++ b/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj @@ -9,7 +9,6 @@ the target version. --> net462;netstandard2.0;net6.0;net7.0;net8.0 true - Serilog.Settings.Configuration serilog;json icon.png README.md @@ -24,12 +23,8 @@ - - - - - - + + diff --git a/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs b/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs index 1049b85..e1f0c84 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 options.WithFilenameGenerator((_, _, fileType, fileExtension) => $"{assembly.GetName().Name!}.{fileType}.{fileExtension}")); diff --git a/test/Serilog.Settings.Configuration.Tests/ConfigurationReaderTests.cs b/test/Serilog.Settings.Configuration.Tests/ConfigurationReaderTests.cs index d235e8f..da01316 100644 --- a/test/Serilog.Settings.Configuration.Tests/ConfigurationReaderTests.cs +++ b/test/Serilog.Settings.Configuration.Tests/ConfigurationReaderTests.cs @@ -185,17 +185,17 @@ public void MethodsAreSelectedBasedOnCountOfMatchedArgumentsAndThenStringType() Assert.Equal(typeof(string), selected?.GetParameters()[2].ParameterType); } - public static IEnumerable 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/Serilog.Settings.Configuration.Tests.csproj b/test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.Tests.csproj index e79a4d5..f9e1e11 100644 --- a/test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.Tests.csproj +++ b/test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.Tests.csproj @@ -18,17 +18,17 @@ - + - - - + + + - + diff --git a/test/Serilog.Settings.Configuration.Tests/Support/ConfigurationReaderTestHelpers.cs b/test/Serilog.Settings.Configuration.Tests/Support/ConfigurationReaderTestHelpers.cs index ae76b43..113432b 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/TestApp/TestApp.csproj b/test/TestApp/TestApp.csproj index b814a4d..2c045b4 100644 --- a/test/TestApp/TestApp.csproj +++ b/test/TestApp/TestApp.csproj @@ -24,7 +24,7 @@ - + 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; diff --git a/test/TestDummies/TestDummies.csproj b/test/TestDummies/TestDummies.csproj index c5be233..c66eed1 100644 --- a/test/TestDummies/TestDummies.csproj +++ b/test/TestDummies/TestDummies.csproj @@ -13,8 +13,4 @@ - - - - From 8df0ec21eb2a31410abd0a3c87e90cd5cf83ec55 Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Mon, 18 Mar 2024 00:16:21 +0300 Subject: [PATCH 2/4] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f0d7f58..ff1faeb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .vs/ +. idea/ bin/ obj/ test/ From 0836e8214a513dc804a9129648385a807c155415 Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Mon, 18 Mar 2024 00:16:54 +0300 Subject: [PATCH 3/4] Update .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ff1faeb..80de031 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ .vs/ -. idea/ +.idea/ bin/ obj/ test/ From c9125c1f3d17e8dffc43539511ccd7c997b0d6e9 Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Mon, 18 Mar 2024 18:38:14 +0300 Subject: [PATCH 4/4] rem --- .../Serilog.Settings.Configuration.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj b/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj index 50bea0b..826faf7 100644 --- a/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj +++ b/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj @@ -23,7 +23,6 @@ -