diff --git a/global.json b/global.json index 3ecc5db..5ce8495 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "8.0.100-rc.2.23502.2" + "version": "8.0.100" } } diff --git a/sample/Sample/Sample.csproj b/sample/Sample/Sample.csproj index ff02fd3..ce3fee4 100644 --- a/sample/Sample/Sample.csproj +++ b/sample/Sample/Sample.csproj @@ -14,15 +14,15 @@ - + - + - - - + + + - + diff --git a/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj b/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj index 43b0a15..c927068 100644 --- a/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj +++ b/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj @@ -26,14 +26,14 @@ - - + + - - + + 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 e7be852..099e89c 100644 --- a/test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.Tests.csproj +++ b/test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.Tests.csproj @@ -17,16 +17,19 @@ - - - - - - - - - - + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/test/TestApp-net48/.gitignore b/test/TestApp-net48/.gitignore new file mode 100644 index 0000000..1cc29f1 --- /dev/null +++ b/test/TestApp-net48/.gitignore @@ -0,0 +1,2 @@ +FodyWeavers.xml +FodyWeavers.xsd diff --git a/test/TestApp-net48/Program.cs b/test/TestApp-net48/Program.cs new file mode 100644 index 0000000..033b43d --- /dev/null +++ b/test/TestApp-net48/Program.cs @@ -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(); +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(); +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; +} diff --git a/test/TestApp-net48/TestApp.csproj b/test/TestApp-net48/TestApp.csproj new file mode 100644 index 0000000..b814a4d --- /dev/null +++ b/test/TestApp-net48/TestApp.csproj @@ -0,0 +1,30 @@ + + + + Exe + net48 + embedded + false + false + false + none + true + true + + + + + + + + + + + + + + + + + + diff --git a/test/TestApp-net48/nuget.config b/test/TestApp-net48/nuget.config new file mode 100644 index 0000000..cfec8fc --- /dev/null +++ b/test/TestApp-net48/nuget.config @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/test/TestApp/TestApp.csproj b/test/TestApp/TestApp.csproj index ebf9791..b814a4d 100644 --- a/test/TestApp/TestApp.csproj +++ b/test/TestApp/TestApp.csproj @@ -22,9 +22,9 @@ - + - + diff --git a/test/TestDummies/DummyPolicy.cs b/test/TestDummies/DummyPolicy.cs index 2104abf..5774510 100644 --- a/test/TestDummies/DummyPolicy.cs +++ b/test/TestDummies/DummyPolicy.cs @@ -1,6 +1,7 @@ using Serilog.Core; using Serilog.Events; using System.Collections; +using System.Diagnostics.CodeAnalysis; namespace TestDummies; @@ -24,7 +25,7 @@ public class DummyPolicy : IDestructuringPolicy public decimal Decimal { get; set; } - public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, out LogEventPropertyValue? result) + public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, [NotNullWhen(true)] out LogEventPropertyValue? result) { result = null; return false; diff --git a/test/TestDummies/TestDummies.csproj b/test/TestDummies/TestDummies.csproj index e410bbb..c5be233 100644 --- a/test/TestDummies/TestDummies.csproj +++ b/test/TestDummies/TestDummies.csproj @@ -5,11 +5,12 @@ - + + - +