Skip to content

Commit 6a8fdb8

Browse files
author
Sergey Komisarchik
committed
skip static constructor on binding for complex parameters types
1 parent bb9a890 commit 6a8fdb8

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* #231 - make '$' sign optional for minimum level / filter switch declarations
1313
* #237 - DependencyContextAssemblyFinder fix: check `serilog` at the start of the name for any dependent package
1414
* #239 - handle NotSupportedException for .net 5.0 single file applications
15+
* #260 - skip static constructor on binding for complex parameters types
1516

1617
3.1.0
1718

README.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static void Main(string[] args)
3535
var configuration = new ConfigurationBuilder()
3636
.SetBasePath(Directory.GetCurrentDirectory())
3737
.AddJsonFile("appsettings.json")
38-
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", true)
38+
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
3939
.Build();
4040

4141
var logger = new LoggerConfiguration()
@@ -74,6 +74,13 @@ var logger = new LoggerConfiguration()
7474

7575
`Using` section contains list of **assemblies** in wich configuration methods (`WriteTo.File()`, `Enrich.WithThreadId()`) resides.
7676

77+
```json
78+
"Serilog": {
79+
"Using": [ "Serilog.Sinks.Console", "Serilog.Enrichers.Thread", /* ... */ ],
80+
// ...
81+
}
82+
```
83+
7784
For .NET Core projects build tools produce `.deps.json` files and this package implements a convention using `Microsoft.Extensions.DependencyModel` to find any package among dependencies with `Serilog` anywhere in the name and pulls configuration methods from it, so the `Using` section in example above can be ommitted:
7885

7986
```json
@@ -106,11 +113,11 @@ var logger = new LoggerConfiguration()
106113

107114
For legacy .NET Framework projects it also scans default probing path(s).
108115

109-
For all other cases, as well as in the case of non-conventional configuration assembly names **DO** use `Using` section.
116+
For all other cases, as well as in the case of non-conventional configuration assembly names **DO** use [Using](#using-section-and-auto-discovery-of-configuration-assemblies) section.
110117

111118
#### .NET 5.0 Single File Applications
112119

113-
Currently, auto-discovery of configuration assemblies is not supported in bundled mode. Use `Using` section for workaround.
120+
Currently, auto-discovery of configuration assemblies is not supported in bundled mode. **DO** use [Using](#using-section-and-auto-discovery-of-configuration-assemblies) section for workaround.
114121

115122
### MinimumLevel, LevelSwitches, overrides and dynamic reload
116123

src/Serilog.Settings.Configuration/Settings/Configuration/StringArgumentValue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public object ConvertTo(Type toType, ResolutionContext resolutionContext)
104104
throw new InvalidOperationException($"Type {argumentValue} was not found.");
105105
}
106106

107-
var ctor = type.GetTypeInfo().DeclaredConstructors.FirstOrDefault(ci =>
107+
var ctor = type.GetTypeInfo().DeclaredConstructors.Where(ci => !ci.IsStatic).FirstOrDefault(ci =>
108108
{
109109
var parameters = ci.GetParameters();
110110
return parameters.Length == 0 || parameters.All(pi => pi.HasDefaultValue);

test/TestDummies/DummyThreadIdEnricher.cs

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ namespace TestDummies
55
{
66
public class DummyThreadIdEnricher : ILogEventEnricher
77
{
8+
static DummyThreadIdEnricher()
9+
{
10+
}
11+
812
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
913
{
1014
logEvent.AddPropertyIfAbsent(propertyFactory

0 commit comments

Comments
 (0)