-
Notifications
You must be signed in to change notification settings - Fork 131
Fixes #97, #83, #98 #100
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
Fixes #97, #83, #98 #100
Changes from 9 commits
bbf9b45
7e14841
90b87ba
82375c0
80b2ec9
1239fda
a81d1c6
60cf699
da883fa
400b1de
f9754e4
0b3b661
0116625
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,3 +91,41 @@ 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. These must be "hinted" by appending a `>` character to the end of the argument name. 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like a bit of a UX regression, and it's not immediately clear when this will or won't be a breaking change; can't we work out what kind of argument we're dealing with by reflecting over the parameters? I am afraid I'm missing something here, sorry - struggling to keep up :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll take another look, but other than the Async wrapper package, frankly I'm not clear on the use cases for nested config. (For example, the reason for the logger nested config in the sample code and tests makes no sense to me.) I don't really like the hack myself, but at the point the code is "deciding" how to store the config section (the parameter value, effectively), we don't yet know what the parameter type is. "How to store" means the various parameter-value classes (string, config, or my new object class). I suspect the config value class can go away and that can be added to the object value class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. Very glad you questioned this -- the "hint" hack is gone and the code is simplified! I took another look at what was going on in This made me notice #103 |
||
|
||
Note the `configure>` parameter name with the trailing hint character: | ||
|
||
```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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👏 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think in the long run that one is going to be very useful to sink authors. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,10 @@ | |
<PackageProjectUrl>https://github.com/serilog/serilog-settings-configuration</PackageProjectUrl> | ||
<PackageLicenseUrl>https://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl> | ||
<RootNamespace>Serilog</RootNamespace> | ||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> | ||
<Version>3.0.0</Version> | ||
<AssemblyVersion>3.0.0</AssemblyVersion> | ||
<FileVersion>3.0.0</FileVersion> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think these should be necessary - will have a shot now at getting this to build without them, then merge 👍 |
||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
|
@@ -26,10 +30,12 @@ | |
|
||
<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> | ||
|
||
</Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the additional docs 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to remove nested config "hint" hack -- but I left the blurb there about nested config support, figured it can't hurt to document it.