Skip to content

skip static constructor on binding for complex parameters types #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* #231 - make '$' sign optional for minimum level / filter switch declarations
* #237 - DependencyContextAssemblyFinder fix: check `serilog` at the start of the name for any dependent package
* #239 - handle NotSupportedException for .net 5.0 single file applications
* #260 - skip static constructor on binding for complex parameters types

3.1.0

Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static void Main(string[] args)
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", true)
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
.Build();

var logger = new LoggerConfiguration()
Expand Down Expand Up @@ -74,6 +74,13 @@ var logger = new LoggerConfiguration()

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

```json
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Enrichers.Thread", /* ... */ ],
// ...
}
```

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:

```json
Expand Down Expand Up @@ -106,11 +113,11 @@ var logger = new LoggerConfiguration()

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

For all other cases, as well as in the case of non-conventional configuration assembly names **DO** use `Using` section.
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.

#### .NET 5.0 Single File Applications

Currently, auto-discovery of configuration assemblies is not supported in bundled mode. Use `Using` section for workaround.
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.

### MinimumLevel, LevelSwitches, overrides and dynamic reload

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public object ConvertTo(Type toType, ResolutionContext resolutionContext)
throw new InvalidOperationException($"Type {argumentValue} was not found.");
}

var ctor = type.GetTypeInfo().DeclaredConstructors.FirstOrDefault(ci =>
var ctor = type.GetTypeInfo().DeclaredConstructors.Where(ci => !ci.IsStatic).FirstOrDefault(ci =>
{
var parameters = ci.GetParameters();
return parameters.Length == 0 || parameters.All(pi => pi.HasDefaultValue);
Expand Down
4 changes: 4 additions & 0 deletions test/TestDummies/DummyThreadIdEnricher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ namespace TestDummies
{
public class DummyThreadIdEnricher : ILogEventEnricher
{
static DummyThreadIdEnricher()
{
}

public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
logEvent.AddPropertyIfAbsent(propertyFactory
Expand Down