Skip to content

Commit

Permalink
Merge pull request #414 from sungam3r/cleanup
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
nblumhardt authored Dec 3, 2024
2 parents afeb558 + 7b32725 commit dfb4df4
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 242 deletions.
203 changes: 3 additions & 200 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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<Assembly> _configurationAssemblies;
Expand Down Expand Up @@ -218,7 +218,7 @@ void ApplyMinimumLevelConfiguration(IConfigurationSection directive, Action<Logg
}
}

void SubscribeToLoggingLevelChanges(IConfigurationSection levelSection, LoggingLevelSwitch levelSwitch)
static void SubscribeToLoggingLevelChanges(IConfigurationSection levelSection, LoggingLevelSwitch levelSwitch)
{
ChangeToken.OnChange(
levelSection.GetReloadToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ bool TryCreateContainer([NotNullWhen(true)] out object? result)
{
var argumentValue = FromSection(section, _configurationAssemblies);
var value = argumentValue.ConvertTo(elementType, resolutionContext);
addMethod.Invoke(result, new[] { value });
addMethod.Invoke(result, [value]);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void AddFilterSwitch(string filterSwitchName, LoggingFilterSwitchProxy fi
_declaredFilterSwitches[referenceName] = filterSwitch;
}

string ToSwitchReference(string switchName)
static string ToSwitchReference(string switchName)
{
return switchName.StartsWith("$") ? switchName : $"${switchName}";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,17 @@ public void MethodsAreSelectedBasedOnCountOfMatchedArgumentsAndThenStringType()
Assert.Equal(typeof(string), selected?.GetParameters()[2].ParameterType);
}

public static IEnumerable<object[]> FlatMinimumLevel => new List<object[]>
{
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<string, string?> {{minimumLevelFlatKey, LogEventLevel.Error.ToString()}}), LogEventLevel.Error},
new object[] { GetConfigRoot(
public static IEnumerable<object[]> FlatMinimumLevel =>
[
[GetConfigRoot(appsettingsJsonLevel: minimumLevelFlatTemplate.Format(LogEventLevel.Error)), LogEventLevel.Error],
[GetConfigRoot(appsettingsDevelopmentJsonLevel: minimumLevelFlatTemplate.Format(LogEventLevel.Error)), LogEventLevel.Error],
[GetConfigRoot(envVariables: new Dictionary<string, string?> {{minimumLevelFlatKey, LogEventLevel.Error.ToString()}}), LogEventLevel.Error],
[GetConfigRoot(
appsettingsJsonLevel: minimumLevelFlatTemplate.Format(LogEventLevel.Debug),
envVariables: new Dictionary<string, string?> {{minimumLevelFlatKey, LogEventLevel.Error.ToString()}}),
LogEventLevel.Error
}
};
]
];

[Theory]
[MemberData(nameof(FlatMinimumLevel))]
Expand All @@ -209,17 +209,17 @@ public void FlatMinimumLevelCorrectOneIsEnabledOnLogger(IConfigurationRoot root,
AssertLogEventLevels(loggerConfig, expectedMinimumLevel);
}

public static IEnumerable<object[]> ObjectMinimumLevel => new List<object[]>
{
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<string, string?>{{minimumLevelObjectKey, LogEventLevel.Error.ToString() } }), LogEventLevel.Error },
new object[] { GetConfigRoot(
public static IEnumerable<object[]> 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<string, string?>{{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))]
Expand All @@ -234,34 +234,31 @@ 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<object[]> MixedMinimumLevel => new List<object[]>
{
new object[]
{
public static IEnumerable<object[]> 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<string, string?>()
{
{minimumLevelObjectKey, LogEventLevel.Error.ToString()},
{minimumLevelFlatKey, LogEventLevel.Debug.ToString()}
}),
LogEventLevel.Debug
}
};
]
];

[Theory]
[MemberData(nameof(MixedMinimumLevel))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static IConfigurationRoot GetConfigRoot(

configBuilder.AddJsonString(appsettingsJsonLevel ?? "{}");
configBuilder.AddJsonString(appsettingsDevelopmentJsonLevel ?? "{}");
configBuilder.Add(new ReloadableConfigurationSource(envVariables ?? new Dictionary<string, string?>()));
configBuilder.Add(new ReloadableConfigurationSource(envVariables ?? []));

return configBuilder.Build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public TestApp(IMessageSink messageSink)
{
file.CopyTo(_workingDirectory.File(file.Name).FullName, overwrite: true);
}
_executables = new Dictionary<PublishMode, FileInfo>();
_executables = [];
}

async Task IAsyncLifetime.InitializeAsync()
Expand Down
2 changes: 1 addition & 1 deletion test/TestDummies/Console/DummyConsoleSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public DummyConsoleSink(ConsoleTheme? theme = null)
[ThreadStatic]
static List<LogEvent>? EmittedList;

public static List<LogEvent> Emitted => EmittedList ??= new List<LogEvent>();
public static List<LogEvent> Emitted => EmittedList ??= [];

public void Emit(LogEvent logEvent)
{
Expand Down
2 changes: 1 addition & 1 deletion test/TestDummies/DummyConfigurationSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class DummyConfigurationSink : ILogEventSink
[ThreadStatic]
static IConfigurationSection? _configSection;

public static List<LogEvent> Emitted => _emitted ?? (_emitted = new List<LogEvent>());
public static List<LogEvent> Emitted => _emitted ?? (_emitted = []);

public static IConfiguration? Configuration => _configuration;

Expand Down
2 changes: 1 addition & 1 deletion test/TestDummies/DummyPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyV

public class CustomCollection<T> : IEnumerable<T>
{
private readonly List<T> inner = new List<T>();
private readonly List<T> inner = [];

public void Add(T item) => inner.Add(item);

Expand Down
2 changes: 1 addition & 1 deletion test/TestDummies/DummyRollingFileAuditSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class DummyRollingFileAuditSink : ILogEventSink
[ThreadStatic]
static List<LogEvent>? _emitted;

public static List<LogEvent> Emitted => _emitted ??= new List<LogEvent>();
public static List<LogEvent> Emitted => _emitted ??= [];

public void Emit(LogEvent logEvent)
{
Expand Down
Loading

0 comments on commit dfb4df4

Please sign in to comment.