-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #445 from nblumhardt/dotnet-9-build-fixes
Try to get `TestApp` running happily in the new build configuration
- Loading branch information
Showing
6 changed files
with
118 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FodyWeavers.xml | ||
FodyWeavers.xsd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System.Reflection; | ||
using Microsoft.Extensions.Configuration; | ||
using Serilog; | ||
using Serilog.Debugging; | ||
using Serilog.Settings.Configuration; | ||
|
||
if (args.Length == 1 && args[0] == "is-single-file") | ||
{ | ||
if (typeof(Program).Assembly.GetManifestResourceNames().Any(e => e.StartsWith("costura."))) | ||
{ | ||
Console.WriteLine(true); | ||
return 0; | ||
} | ||
// IL3000: 'System.Reflection.Assembly.Location' always returns an empty string for assemblies embedded in a single-file app | ||
#pragma warning disable IL3000 | ||
Console.WriteLine(string.IsNullOrEmpty(Assembly.GetEntryAssembly()?.Location)); | ||
#pragma warning restore | ||
return 0; | ||
} | ||
|
||
SelfLog.Enable(Console.Error); | ||
|
||
Thread.CurrentThread.Name = "Main thread"; | ||
const string outputTemplate = "({ThreadName}) [{Level}] {Message}{NewLine}"; | ||
|
||
var configurationValues = new Dictionary<string, string?>(); | ||
var minimumLevelOnly = args.Contains("--minimum-level-only"); | ||
if (minimumLevelOnly) | ||
{ | ||
configurationValues["Serilog:MinimumLevel"] = "Verbose"; | ||
} | ||
else | ||
{ | ||
configurationValues["Serilog:Enrich:0"] = "WithThreadName"; | ||
configurationValues["Serilog:WriteTo:0:Name"] = "Console"; | ||
configurationValues["Serilog:WriteTo:0:Args:outputTemplate"] = outputTemplate; | ||
} | ||
|
||
if (args.Contains("--using-thread")) configurationValues["Serilog:Using:Thread"] = "Serilog.Enrichers.Thread"; | ||
if (args.Contains("--using-console")) configurationValues["Serilog:Using:Console"] = "Serilog.Sinks.Console"; | ||
|
||
var assemblies = new List<Assembly>(); | ||
if (args.Contains("--assembly-thread")) assemblies.Add(typeof(ThreadLoggerConfigurationExtensions).Assembly); | ||
if (args.Contains("--assembly-console")) assemblies.Add(typeof(ConsoleLoggerConfigurationExtensions).Assembly); | ||
|
||
try | ||
{ | ||
var configuration = new ConfigurationBuilder().AddInMemoryCollection(configurationValues).Build(); | ||
var options = assemblies.Count > 0 ? new ConfigurationReaderOptions(assemblies.ToArray()) : null; | ||
var loggerConfiguration = new LoggerConfiguration().ReadFrom.Configuration(configuration, options); | ||
if (minimumLevelOnly) | ||
{ | ||
loggerConfiguration | ||
.Enrich.WithThreadName() | ||
.WriteTo.Console(outputTemplate: outputTemplate); | ||
} | ||
var logger = loggerConfiguration.CreateLogger(); | ||
logger.Information("Expected success"); | ||
return 0; | ||
} | ||
catch (InvalidOperationException exception) when (exception.Message.StartsWith("No Serilog:Using configuration section is defined and no Serilog assemblies were found.")) | ||
{ | ||
Console.WriteLine("Expected exception"); | ||
return 0; | ||
} | ||
catch (Exception exception) | ||
{ | ||
Console.Error.WriteLine(exception); | ||
return 1; | ||
} |
Binary file added
BIN
+92.9 KB
test/TestApp-net9.0/Serilog.Settings.Configuration.0.0.0-IntegrationTest.0.snupkg
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net48</TargetFramework> | ||
<DebugType>embedded</DebugType> | ||
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects> | ||
<GenerateSupportedRuntime>false</GenerateSupportedRuntime> | ||
<PublishReferencesDocumentationFiles>false</PublishReferencesDocumentationFiles> | ||
<AllowedReferenceRelatedFileExtensions>none</AllowedReferenceRelatedFileExtensions> | ||
<UseCurrentRuntimeIdentifier>true</UseCurrentRuntimeIdentifier> | ||
<SelfContained>true</SelfContained> | ||
<GenerateDocumentationFile>false</GenerateDocumentationFile> | ||
<!-- Ignore vulnerable (framework) packages; this app is not published. --> | ||
<NoWarn>NU1902;NU1903</NoWarn> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Condition="$(Configuration) == 'Debug'"> | ||
<ProjectReference Include="..\..\src\Serilog.Settings.Configuration\Serilog.Settings.Configuration.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="$(Configuration) == 'Release'"> | ||
<PackageReference Include="Serilog.Settings.Configuration" Version="[0.0.0-IntegrationTest.0]" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Costura.Fody" Version="5.7.0" PrivateAssets="all" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" /> | ||
<PackageReference Include="Serilog.Enrichers.Thread" Version="4.0.0" /> | ||
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<config> | ||
<add key="globalPackagesFolder" value="packages" /> | ||
</config> | ||
<packageSources> | ||
<clear /> | ||
<add key="local" value="." /> | ||
<add key="nuget" value="https://api.nuget.org/v3/index.json" /> | ||
</packageSources> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters