Skip to content
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

3.0 Release #112

Merged
merged 79 commits into from
Oct 7, 2018
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
f724410
Dev (major) version bump, updating dependency versions
nblumhardt Mar 14, 2018
5f35b90
Travis build files and update to NetCore 2.
merbla Apr 4, 2018
aabcbd3
Added Sample to build on Travis.
merbla Apr 4, 2018
e0ac44f
Fixes #91 - wrong parameter names on surrogate WriteTo.Logger() confi…
nblumhardt Mar 15, 2018
a201884
Added tests from #91 comments
merbla Apr 5, 2018
30fe458
Allowed exit on Sample app for build.
merbla Apr 5, 2018
b1668ab
Remove .Net Core 1 install scripts.
merbla Apr 5, 2018
0097364
Set execute permissions on build.
merbla Apr 5, 2018
6c9d9dc
README: Use `Console` instead of `LiterateConsole`
adamchester Apr 5, 2018
99fa29d
Merge pull request #95 from serilog/adamchester-patch-1
nblumhardt Apr 5, 2018
26b2c7b
Merge pull request #94 from merbla/tooling-updates
nblumhardt Apr 5, 2018
4bf535c
project files updated
MV10 Apr 10, 2018
8ccd28c
update to netstandard2.0
MV10 Apr 10, 2018
9489ad4
removed APPDOMAIN constant
MV10 Apr 11, 2018
f396e87
Merge pull request #96 from MV10/netstandard2_0
nblumhardt Apr 11, 2018
bbf9b45
Merge pull request #1 from serilog/dev
MV10 Apr 12, 2018
7e14841
minor formatting cleanup; rollback of direct parm value during method…
MV10 Apr 17, 2018
90b87ba
changed null-ref checks to Any() tests on GetSection results
MV10 Apr 17, 2018
82375c0
confing binding and config section hinting
MV10 Apr 18, 2018
80b2ec9
populate value for an IConfiguration parameter on target method
MV10 Apr 18, 2018
1239fda
recognize IConfigurationSection parameter types
MV10 Apr 19, 2018
a81d1c6
docs for IConfigurationSection
MV10 Apr 19, 2018
60cf699
renamed const to NestedConfigHintChar
MV10 Apr 19, 2018
da883fa
fixed unit tests with config subsections
MV10 Apr 19, 2018
400b1de
moved ConfigurationSectionArgumentValue functionality into ObjectArgu…
MV10 Apr 20, 2018
f9754e4
unit test for IConfig, IConfigSection, and config object-binding
MV10 Apr 20, 2018
0b3b661
unit tests for string/int array arguments
MV10 Apr 20, 2018
0116625
Try removing pinned <Version> properties, etc, to match general Seril…
nblumhardt Apr 21, 2018
62acc84
Merge pull request #100 from MV10/iconfig_parameter
nblumhardt Apr 21, 2018
7b18eef
added exception
MV10 Apr 28, 2018
99cb4af
unit test for multiple conflicting argument values
MV10 Apr 28, 2018
36df0a6
code formatting
MV10 Apr 28, 2018
5e6d67d
verbiage and naming feedback
MV10 Apr 28, 2018
67e7ca8
more detailed test assertion and change text to match new exception
MV10 Apr 28, 2018
e9dfb98
Merge pull request #105 from MV10/multiple-value-exception
nblumhardt Apr 30, 2018
76b0bf2
support the basic destructure settings
MV10 May 6, 2018
4ab6ec0
added destructure section to sample json
MV10 May 6, 2018
43345f1
PR feedback, and added IDestructuringPolicy to sample program and README
MV10 May 7, 2018
285a4ce
New NuGet API key
merbla May 9, 2018
6a56899
Merge pull request #110 from MV10/destructuring
tsimbalar May 14, 2018
930f014
Merge changes made in master back to dev
tsimbalar Jul 9, 2018
17d8083
Add test to check support for custom destructuring extension Methods
tsimbalar Jul 14, 2018
c5731c9
fix ReSharper warning
tsimbalar Jul 14, 2018
2426487
Reformat / light refactor in ConfigurationReader
tsimbalar Jul 14, 2018
761f014
Add support for handling arguments of type Type
tsimbalar Jul 14, 2018
fac151f
Expose Destructure.AsScalar(Type scalarType) to the configuration
tsimbalar Jul 14, 2018
d9d6cec
Refactor ConfigurationReader and move Surrogate methods to a separate…
tsimbalar Jul 15, 2018
74fb413
Merge pull request #120 from tsimbalar/destructure-asscalar
tsimbalar Jul 18, 2018
f9a0c5c
Build a package version for net461
alastairs Jul 26, 2018
a6177b7
Merge pull request #124 from alastairs/bug/123/fix-net451-dependencies
MV10 Jul 28, 2018
5cb8e92
fixes #111 - case-insensitive method argument-matching
MV10 Aug 29, 2018
0095855
unit test for case-insensitive argument matching
MV10 Aug 29, 2018
268b719
fixes #131 by preferring string overloaded methods
nbaztec Sep 10, 2018
1ee618a
Merge pull request #128 from MV10/issue_111
MV10 Sep 16, 2018
54ddc84
fixing repository url
MaximRouiller Sep 21, 2018
d6118bf
Merge pull request #134 from MaximRouiller/repositoryurl
nblumhardt Sep 22, 2018
cdbc7c3
Merge branch 'dev' into fix-issue/131
nbaztec Sep 29, 2018
da8a883
fixes typo
nbaztec Sep 29, 2018
578cfc1
fixe typo
nbaztec Sep 29, 2018
fbe4f2f
Merge pull request #132 from nbaztec/fix-issue/131
MV10 Sep 29, 2018
cae987a
fixes #63 - option to control assembly source
MV10 Sep 29, 2018
0d4b69e
moved test to avoid parallel test conflicts
MV10 Sep 29, 2018
1f24471
PR feedback
MV10 Oct 3, 2018
1a46ac7
filename/location tweak per feedback
MV10 Oct 5, 2018
4db7753
Merge pull request #136 from MV10/issue_63
nblumhardt Oct 5, 2018
35ff174
removed unnecessary package ref
MV10 Oct 6, 2018
bd98efc
Merge pull request #138 from MV10/pr_112
MV10 Oct 6, 2018
818f08f
Remove unused class `ConfigurationValueSyntax`
tsimbalar Oct 6, 2018
2fe5f4f
Minor refactoring to properly reset static properties
tsimbalar Oct 6, 2018
b98aba2
Add support for WriteTo.Sink()
tsimbalar Oct 6, 2018
ed9c049
Add support for AuditTo.Sink()
tsimbalar Oct 6, 2018
0b3b739
Add support for Enrich.With()
tsimbalar Oct 6, 2018
70e4f0b
Add test for support Filter.With()
tsimbalar Oct 6, 2018
a55fc9f
Refactor `SurrogateConfigurationMethods`
tsimbalar Oct 6, 2018
01b1cfd
Minor reformatting and documentation
tsimbalar Oct 6, 2018
cf81e5a
Mark as private the members that are not used elsewhere
tsimbalar Oct 6, 2018
4c932e4
Minor whitespace reformatting
tsimbalar Oct 6, 2018
a1eda73
Merge pull request #139 from tsimbalar/remove-unused-configurationval…
nblumhardt Oct 7, 2018
9f28bbc
Merge pull request #140 from tsimbalar/add-supported-methods
nblumhardt Oct 7, 2018
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,6 @@ FakesAssemblies/
*.opt

project.lock.json

#Test files
*.txt
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: csharp

matrix:
include:
- os: linux
dist: trusty
sudo: required
dotnet: 2.1.4
group: edge
script:
- ./build.sh
50 changes: 46 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,27 @@ Configuration is read from the `Serilog` section.
```json
{
"Serilog": {
"Using": ["Serilog.Sinks.Literate"],
"Using": ["Serilog.Sinks.Console"],
"MinimumLevel": "Debug",
"WriteTo": [
{ "Name": "LiterateConsole" },
{ "Name": "Console" },
{ "Name": "File", "Args": { "path": "%TEMP%\\Logs\\serilog-configuration-sample.txt" } }
],
"Enrich": ["FromLogContext", "WithMachineName", "WithThreadId"],
"Destructure": [
{ "Name": "With", "Args": { "policy": "Sample.CustomPolicy, Sample" } },
{ "Name": "ToMaximumDepth", "Args": { "maximumDestructuringDepth": 4 } },
{ "Name": "ToMaximumStringLength", "Args": { "maximumStringLength": 100 } },
{ "Name": "ToMaximumCollectionCount", "Args": { "maximumCollectionCount": 10 } }
],
"Properties": {
"Application": "Sample"
}
}
}
```

This example relies on the _Serilog.Sinks.Literate_, _Serilog.Sinks.File_, _Serilog.Enrichers.Environment_, _Serilog.Settings.Configuration_ and _Serilog.Enrichers.Thread_ packages also being installed.
This example relies on the _Serilog.Sinks.Console_, _Serilog.Sinks.File_, _Serilog.Enrichers.Environment_, _Serilog.Settings.Configuration_ and _Serilog.Enrichers.Thread_ packages also being installed.

After installing this package, use `ReadFrom.Configuration()` and pass an `IConfiguration` object.

Expand All @@ -46,7 +52,7 @@ public class Program
The `WriteTo` and `Enrich` sections support the same syntax, for example the following is valid if no arguments are needed by the sinks:

```json
"WriteTo": ["LiterateConsole", "DiagnosticTrace"]
"WriteTo": ["Console", "DiagnosticTrace"]
```

Or alternatively, the long-form (`"Name":` ...) syntax from the first example can be used when arguments need to be supplied.
Expand Down Expand Up @@ -91,3 +97,39 @@ For example, to set the minimum log level using the _Windows_ command prompt:
set Serilog:MinimumLevel=Debug
dotnet run
```

### Nested configuration sections

Some Serilog packages require a reference to a logger configuration object. The sample program in this project illustrates this with the following entry configuring the _Serilog.Sinks.Async_ package to wrap the _Serilog.Sinks.File_ package. The `configure` parameter references the File sink configuration:

```json
"WriteTo:Async": {
"Name": "Async",
"Args": {
"configure": [
{
"Name": "File",
"Args": {
"path": "%TEMP%\\Logs\\serilog-configuration-sample.txt",
"outputTemplate": "{Timestamp:o} [{Level:u3}] ({Application}/{MachineName}/{ThreadId}) {Message}{NewLine}{Exception}"
}
}
]
}
},
```

### IConfiguration parameter

If a Serilog package requires additional external configuration information (for example, access to a `ConnectionStrings` section, which would be outside of the `Serilog` section), the sink should include an `IConfiguration` parameter in the configuration extension method. This package will automatically populate that parameter. It should not be declared in the argument list in the configuration source.

### Complex parameter value binding

When the configuration specifies a discrete value for a parameter (such as a string literal), the package will attempt to convert that value to the target method's declared CLR type of the parameter. Additional explicit handling is provided for parsing strings to `Uri` and `TimeSpan` objects and `enum` elements.

If the parameter value is not a discrete value, the package will use the configuration binding system provided by _Microsoft.Extensions.Options.ConfigurationExtensions_ to attempt to populate the parameter. Almost anything that can be bound by `IConfiguration.Get<T>` should work with this package. An example of this is the optional `List<Column>` parameter used to configure the .NET Standard version of the _Serilog.Sinks.MSSqlServer_ package.

### IConfigurationSection parameters

Certain Serilog packages may require configuration information that can't be easily represented by discrete values or direct binding-friendly representations. An example might be lists of values to remove from a collection of default values. In this case the method can accept an entire `IConfigurationSection` as a call parameter and this package will recognize that and populate the parameter. In this way, Serilog packages can support arbitrarily complex configuration scenarios.

10 changes: 2 additions & 8 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ version: '{build}'
skip_tags: true
image: Visual Studio 2017
configuration: Release
install:
- ps: mkdir -Force ".\build\" | Out-Null
- ps: Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/dotnet-install.ps1" -OutFile ".\build\installcli.ps1"
- ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetcli"
- ps: '& .\build\installcli.ps1 -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath -Version 1.0.1'
- ps: $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path"
build_script:
- ps: ./Build.ps1
test: off
Expand All @@ -16,7 +10,7 @@ artifacts:
deploy:
- provider: NuGet
api_key:
secure: nvZ/z+pMS91b3kG4DgfES5AcmwwGoBYQxr9kp4XiJHj25SAlgdIxFx++1N0lFH2x
secure: bd9z4P73oltOXudAjPehwp9iDKsPtC+HbgshOrSgoyQKr5xVK+bxJQngrDJkHdY8
skip_symbols: true
on:
branch: /^(master|dev)$/
Expand All @@ -26,4 +20,4 @@ deploy:
artifact: /Serilog.*\.nupkg/
tag: v$(appveyor_build_version)
on:
branch: master
branch: master
17 changes: 17 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -e
dotnet --info
dotnet restore

for path in src/**/*.csproj; do
dotnet build -f netstandard2.0 -c Release ${path}
done

for path in test/*.Tests/*.csproj; do
dotnet test -f netcoreapp2.0 -c Release ${path}
done

cd sample/Sample/
dotnet build -f netcoreapp2.0 -c Release
dotnet bin/Release/netcoreapp2.0/Sample.dll --run-once
48 changes: 45 additions & 3 deletions sample/Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
using Microsoft.Extensions.Configuration;
using Serilog;
using System.IO;

using System.Linq;
using Serilog.Core;
using Serilog.Events;
using System.Collections.Generic;

namespace Sample
{
Expand All @@ -22,6 +23,8 @@ public static void Main(string[] args)
.ReadFrom.Configuration(configuration)
.CreateLogger();

logger.Information("Args: {a}", args);

do
{
logger.ForContext<Program>().Information("Hello, world!");
Expand All @@ -30,17 +33,56 @@ public static void Main(string[] args)
logger.ForContext(Constants.SourceContextPropertyName, "Microsoft").Error("Hello, world!");
logger.ForContext(Constants.SourceContextPropertyName, "MyApp.Something.Tricky").Verbose("Hello, world!");

Console.WriteLine();
logger.Information("Destructure with max object nesting depth:\n{@NestedObject}",
new { FiveDeep = new { Two = new { Three = new { Four = new { Five = "the end" } } } } });

logger.Information("Destructure with max string length:\n{@LongString}",
new { TwentyChars = "0123456789abcdefghij" });

logger.Information("Destructure with max collection count:\n{@BigData}",
new { TenItems = new[] { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" } });

logger.Information("Destructure with policy to strip password:\n{@LoginData}",
new LoginData { Username = "BGates", Password = "isityearoflinuxyet" });

Console.WriteLine("\nPress \"q\" to quit, or any other key to run again.\n");
}
while (Console.ReadKey().KeyChar != 'q');
while(!args.Contains("--run-once") && (Console.ReadKey().KeyChar != 'q'));
}
}

// The filter syntax in the sample configuration file is
// processed by the Serilog.Filters.Expressions package.
public class CustomFilter : ILogEventFilter
{
public bool IsEnabled(LogEvent logEvent)
{
return true;
}
}

public class LoginData
{
public string Username;
public string Password;
}

public class CustomPolicy : IDestructuringPolicy
{
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, out LogEventPropertyValue result)
{
result = null;

if(value is LoginData)
{
result = new StructureValue(
new List<LogEventProperty>
{
new LogEventProperty("Username", new ScalarValue(((LoginData)value).Username))
});
}

return (result != null);
}
}
}
11 changes: 9 additions & 2 deletions sample/Sample/Sample.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net46;netcoreapp1.0</TargetFrameworks>
<TargetFrameworks>net46;netcoreapp2.0</TargetFrameworks>
<OutputType>Exe</OutputType>
</PropertyGroup>

Expand All @@ -13,8 +13,15 @@
<ProjectReference Include="..\..\src\Serilog.Settings.Configuration\Serilog.Settings.Configuration.csproj" />
</ItemGroup>

<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net46'">
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.1" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Serilog.Sinks.Async" Version="1.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.0.0" />
Expand Down
18 changes: 18 additions & 0 deletions sample/Sample/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@
"Properties": {
"Application": "Sample"
},
"Destructure": [
{
"Name": "With",
"Args": { "policy": "Sample.CustomPolicy, Sample" }
},
{
"Name": "ToMaximumDepth",
"Args": { "maximumDestructuringDepth": 3 }
},
{
"Name": "ToMaximumStringLength",
"Args": { "maximumStringLength": 10 }
},
{
"Name": "ToMaximumCollectionCount",
"Args": { "maximumCollectionCount": 5 }
}
],
"Filter": [
{
"Name": "ByIncludingOnly",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ namespace Serilog
/// </summary>
public static class ConfigurationLoggerConfigurationExtensions
{
const string DefaultSectionName = "Serilog";
/// <summary>
/// Configuration section name required by this package.
/// </summary>
public const string DefaultSectionName = "Serilog";

/// <summary>
/// Reads logger settings from the provided configuration object using the default section name.
/// Reads logger settings from the provided configuration object using the default section name. Generally this
/// is preferable over the other method that takes a configuration section. Only this version will populate
/// IConfiguration parameters on target methods.
/// </summary>
/// <param name="settingConfiguration">Logger setting configuration.</param>
/// <param name="configuration">A configuration object with a Serilog section.</param>
/// <param name="configuration">A configuration object which contains a Serilog section.</param>
/// <param name="dependencyContext">The dependency context from which sink/enricher packages can be located. If not supplied, the platform
/// default will be used.</param>
/// <returns>An object allowing configuration to continue.</returns>
Expand All @@ -42,28 +47,32 @@ public static LoggerConfiguration Configuration(
DependencyContext dependencyContext = null)
{
if (configuration == null) throw new ArgumentNullException(nameof(configuration));
return settingConfiguration.ConfigurationSection(configuration.GetSection(DefaultSectionName), dependencyContext);
return settingConfiguration.Settings(
new ConfigurationReader(
configuration,
dependencyContext ?? (Assembly.GetEntryAssembly() != null ? DependencyContext.Default : null)));
}

/// <summary>
/// Reads logger settings from the provided configuration section.
/// Reads logger settings from the provided configuration section. Generally it is preferable to use the other
/// extension method that takes the full configuration object.
/// </summary>
/// <param name="settingConfiguration">Logger setting configuration.</param>
/// <param name="configuration">The Serilog configuration section</param>
/// <param name="configSection">The Serilog configuration section</param>
/// <param name="dependencyContext">The dependency context from which sink/enricher packages can be located. If not supplied, the platform
/// default will be used.</param>
/// <returns>An object allowing configuration to continue.</returns>
public static LoggerConfiguration ConfigurationSection(
this LoggerSettingsConfiguration settingConfiguration,
IConfigurationSection configuration,
IConfigurationSection configSection,
DependencyContext dependencyContext = null)
{
if (settingConfiguration == null) throw new ArgumentNullException(nameof(settingConfiguration));
if (configuration == null) throw new ArgumentNullException(nameof(configuration));
if (configSection == null) throw new ArgumentNullException(nameof(configSection));

return settingConfiguration.Settings(
new ConfigurationReader(
configuration,
configSection,
dependencyContext ?? (Assembly.GetEntryAssembly() != null ? DependencyContext.Default : null)));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<PropertyGroup>
<Description>Microsoft.Extensions.Configuration (appsettings.json) support for Serilog.</Description>
<VersionPrefix>2.6.1</VersionPrefix>
<VersionPrefix>3.0.0</VersionPrefix>
<Authors>Serilog Contributors</Authors>
<TargetFrameworks>net451;netstandard1.6</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net451</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Serilog.Settings.Configuration</AssemblyName>
Expand All @@ -16,20 +16,22 @@
<PackageIconUrl>https://serilog.net/images/serilog-configuration-nuget.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/serilog/serilog-settings-configuration</PackageProjectUrl>
<PackageLicenseUrl>https://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>

<!-- Don't reference the full NETStandard.Library -->
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
<RootNamespace>Serilog</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="2.0.4" />
<PackageReference Include="Serilog" Version="2.6.0" />
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net451' ">
<DefineConstants>$(DefineConstants);APPDOMAIN</DefineConstants>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net451'">
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.2" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.0" />
</ItemGroup>

MV10 marked this conversation as resolved.
Show resolved Hide resolved
</Project>
Loading