Skip to content

Commit 5ac6a59

Browse files
author
Sergey Komisarchik
committed
misc fixes:
- DependencyContextAssemblyFinder convention check fix - .net 5.0 single file application support - TFM's, samples update - reference `Serilog.Expressions` to sample project
1 parent 0624f63 commit 5ac6a59

File tree

10 files changed

+59
-30
lines changed

10 files changed

+59
-30
lines changed

.vscode/launch.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"request": "launch",
1111
"preLaunchTask": "build",
1212
// If you have changed target frameworks, make sure to update the program path.
13-
"program": "${workspaceFolder}/sample/Sample/bin/Debug/netcoreapp2.0/Sample.dll",
13+
"program": "${workspaceFolder}/sample/Sample/bin/Debug/netcoreapp3.1/Sample.dll",
1414
"args": [],
1515
"cwd": "${workspaceFolder}/sample/Sample",
1616
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console

Build.ps1

+14-7
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ echo "build: Build started"
33
Push-Location $PSScriptRoot
44

55
if (Test-Path .\artifacts) {
6-
echo "build: Cleaning .\artifacts"
7-
Remove-Item .\artifacts -Force -Recurse
6+
echo "build: Cleaning .\artifacts"
7+
Remove-Item .\artifacts -Force -Recurse
88
}
99

1010
& dotnet restore --no-cache
@@ -18,7 +18,7 @@ echo "build: Version suffix is $suffix"
1818
foreach ($src in dir src/*) {
1919
Push-Location $src
2020

21-
echo "build: Packaging project in $src"
21+
echo "build: Packaging project in $src"
2222

2323
& dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix -p:ContinuousIntegrationBuild=true
2424
if ($LASTEXITCODE -ne 0) { exit 1 }
@@ -29,7 +29,7 @@ foreach ($src in dir src/*) {
2929
foreach ($test in dir test/*.PerformanceTests) {
3030
Push-Location $test
3131

32-
echo "build: Building performance test project in $test"
32+
echo "build: Building performance test project in $test"
3333

3434
& dotnet build -c Release
3535
if ($LASTEXITCODE -ne 0) { exit 2 }
@@ -40,11 +40,12 @@ foreach ($test in dir test/*.PerformanceTests) {
4040
foreach ($test in dir test/*.Tests) {
4141
Push-Location $test
4242

43-
echo "build: Testing project in $test"
43+
echo "build: Testing project in $test"
4444

4545
if ($PSVersionTable.Platform -eq "Unix") {
46-
& dotnet test -c Release -f netcoreapp2.0
46+
& dotnet test -c Release -f netcoreapp2.1
4747
& dotnet test -c Release -f netcoreapp3.1
48+
& dotnet test -c Release -f net50
4849
} else {
4950
& dotnet test -c Release
5051
}
@@ -57,7 +58,13 @@ foreach ($test in dir test/*.Tests) {
5758
if ($PSVersionTable.Platform -eq "Unix") {
5859
Push-Location sample/Sample
5960

60-
& dotnet run -f netcoreapp2.0 -c Release --run-once
61+
& dotnet run -f netcoreapp2.1 -c Release --run-once
62+
if ($LASTEXITCODE -ne 0) { exit 4 }
63+
64+
& dotnet run -f netcoreapp3.1 -c Release --run-once
65+
if ($LASTEXITCODE -ne 0) { exit 4 }
66+
67+
& dotnet run -f net50 -c Release --run-once
6168
if ($LASTEXITCODE -ne 0) { exit 4 }
6269

6370
Pop-Location

CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* #219 - reduced search graph for configuration dlls to avoid native assets
99
* #221 - added support for conditional/leveled enrichers from Serilog 2.9+
1010
* #222 - updated Microsoft.Extensions.DependencyModel
11+
* #237 - DependencyContextAssemblyFinder fix: check `serilog` in any part of the name for any dependent package
12+
* #239 - handle NotSupportedException for .net 5.0 single file applications
1113

1214
3.1.0
1315

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ For legacy .NET Framework projects it also scans default probing path(s).
107107

108108
For all other cases, as well as in the case of non-conventional configuration assembly names **DO** use `Using` section.
109109

110+
#### .NET 5.0 Single File Applications
111+
112+
Currently, auto-discovery of configuration assemblies is not supported in bundled mode. Use `Using` section for workaround.
113+
110114
### MinimumLevel, LevelSwitches, overrides and dynamic reload
111115

112116
The `MinimumLevel` configuration property can be set to a single value as in the sample above, or, levels can be overridden per logging source.

appveyor.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ version: '{build}'
22
skip_tags: true
33
image:
44
- Visual Studio 2019
5-
- Ubuntu1604
5+
- Ubuntu
66
configuration: Release
77
build_script:
88
- ps: ./Build.ps1
99
for:
1010
-
1111
matrix:
1212
only:
13-
- image: Ubuntu1604
13+
- image: Ubuntu
1414
build_script:
1515
- pwsh ./Build.ps1
1616
test: off

sample/Sample/Sample.csproj

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
4+
<TargetFrameworks>net50;netcoreapp3.1;netcoreapp2.1;net46</TargetFrameworks>
55
<OutputType>Exe</OutputType>
66
</PropertyGroup>
77

@@ -15,10 +15,22 @@
1515

1616
<ItemGroup Condition="'$(TargetFramework)' == 'net46'">
1717
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" />
18+
<PackageReference Include="Serilog.Filters.Expressions" Version="2.1.0" />
19+
</ItemGroup>
20+
21+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
22+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
23+
<PackageReference Include="Serilog.Filters.Expressions" Version="2.1.0" />
1824
</ItemGroup>
1925

20-
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
21-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.1" />
26+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
27+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.10" />
28+
<PackageReference Include="Serilog.Expressions" Version="1.0.0" />
29+
</ItemGroup>
30+
31+
<ItemGroup Condition="'$(TargetFramework)' == 'net50'">
32+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
33+
<PackageReference Include="Serilog.Expressions" Version="1.0.0" />
2234
</ItemGroup>
2335

2436
<ItemGroup>
@@ -27,7 +39,6 @@
2739
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
2840
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.1.3" />
2941
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
30-
<PackageReference Include="Serilog.Filters.Expressions" Version="2.1.0" />
3142
</ItemGroup>
3243

3344
<ItemGroup>

src/Serilog.Settings.Configuration/Settings/Configuration/Assemblies/AssemblyFinder.cs

+11-4
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,19 @@ protected static bool IsCaseInsensitiveMatch(string text, string textToFind)
1616

1717
public static AssemblyFinder Auto()
1818
{
19-
// Need to check `Assembly.GetEntryAssembly()` first because
20-
// `DependencyContext.Default` throws an exception when `Assembly.GetEntryAssembly()` returns null
21-
if (Assembly.GetEntryAssembly() != null && DependencyContext.Default != null)
19+
try
2220
{
23-
return new DependencyContextAssemblyFinder(DependencyContext.Default);
21+
// Need to check `Assembly.GetEntryAssembly()` first because
22+
// `DependencyContext.Default` throws an exception when `Assembly.GetEntryAssembly()` returns null
23+
if (Assembly.GetEntryAssembly() != null && DependencyContext.Default != null)
24+
{
25+
return new DependencyContextAssemblyFinder(DependencyContext.Default);
26+
}
2427
}
28+
catch (NotSupportedException) when (typeof(object).Assembly.Location is "") // bundled mode detection
29+
{
30+
}
31+
2532
return new DllScanningAssemblyFinder();
2633
}
2734

src/Serilog.Settings.Configuration/Settings/Configuration/Assemblies/DependencyContextAssemblyFinder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ where IsCaseInsensitiveMatch(assemblyName.Name, nameToFind)
2727

2828
static bool IsReferencingSerilog(Library library)
2929
{
30-
return library.Dependencies.Any(dependency => dependency.Name.Equals("serilog", StringComparison.OrdinalIgnoreCase));
30+
return library.Dependencies.Any(dependency => dependency.Name.IndexOf("serilog", StringComparison.OrdinalIgnoreCase) >= 0);
3131
}
3232
}
3333
}

test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.Tests.csproj

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp3.1;netcoreapp2.0;net452</TargetFrameworks>
4+
<TargetFrameworks>net50;netcoreapp3.1;netcoreapp2.1;net452</TargetFrameworks>
55
<LangVersion>latest</LangVersion>
66
<AssemblyName>Serilog.Settings.Configuration.Tests</AssemblyName>
77
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
@@ -20,20 +20,22 @@
2020

2121
<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
2222
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.2" />
23-
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="1.1.2" />
2423
</ItemGroup>
2524

26-
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
27-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.1" />
28-
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.0.1" />
25+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
26+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
2927
</ItemGroup>
3028

3129
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
32-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.0" />
30+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.10" />
31+
</ItemGroup>
32+
33+
<ItemGroup Condition="'$(TargetFramework)' == 'net50'">
34+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
3335
</ItemGroup>
3436

3537
<ItemGroup>
36-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
38+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
3739
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
3840
<PackageReference Include="xunit" Version="2.2.0" />
3941
</ItemGroup>

test/Serilog.Settings.Configuration.Tests/Support/Extensions.cs

-4
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@ public static object LiteralValue(this LogEventPropertyValue @this)
99
return ((ScalarValue)@this).Value;
1010
}
1111

12-
// netcore3.0 error:
13-
// Could not parse the JSON file. System.Text.Json.JsonReaderException : ''' is an invalid start of a property name. Expected a '"'
1412
public static string ToValidJson(this string str)
1513
{
16-
#if NETCOREAPP3_1
1714
str = str.Replace('\'', '"');
18-
#endif
1915
return str;
2016
}
2117
}

0 commit comments

Comments
 (0)