-
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
Conversation
sync fork
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.
Great PR, thanks! Looks like we're making some substantial progress. Had some questions. Cheers!
@@ -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 |
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.
README.md
Outdated
|
||
### 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 comment
The 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 comment
The 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 comment
The 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 ConfigurationSectionArgumentValue
and it turns out I could get rid of that and move the functionality into ObjectArgumentValue
. The trick was deferring the new ConfigurationReader
pass to read the nested config until we are actually calling the target method. Now the read is triggered by the Action<>
parameter's type rather than hinting and/or "assuming" based on config structure.
This made me notice #103
|
||
### 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 comment
The 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 comment
The 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.
readonly DependencyContext _dependencyContext; | ||
readonly IReadOnlyCollection<Assembly> _configurationAssemblies; | ||
|
||
public ConfigurationReader(IConfigurationSection configuration, DependencyContext dependencyContext) | ||
#region Constructors |
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.
Nit: the Serilog projects don't use #region
at all :-)
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.
Removed. (Personally I like them...)
@@ -402,7 +402,7 @@ public void WriteToLoggerWithRestrictedToMinimumLevelIsSupported() | |||
""WriteTo"": [{ | |||
""Name"": ""Logger"", | |||
""Args"": { | |||
""configureLogger"" : { | |||
""configureLogger>"" : { |
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.
Just a general note on this file - since arbitrary nested config args can be supported, could we include a test here to demonstrate it? I'm worried that it'd be easy to introduce regressions if we don't have at least a smoke test for that option.
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.
That test already checks nested configs (there are two of them). Not clear what else you're asking for. However, it probably does need a test for IConfigurationSection
and maybe another for config binding, such as List<T>
... I'm still not clear how some of the test "dummy" sinks actually work though, seems overly complicated. I wish there were comments. But I'll have a look.
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.
Tests added and passing on both frameworks, and the revised nested config implementation also passes.
@nblumhardt Not sure what happened to our comments about that The hack is gone. Basically I got rid of Added unit tests, too, so that covers everything. |
<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 comment
The 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 👍
Awesome PR! Just going to check that the build goes through with my minor CSPROJ tweak, then will merge. The PR comment "disappearing" trick is a bit of an annoying UI default in GitHub - once the code in question has changed, the comments on it are hidden by default. Cheers! |
@nblumhardt Awesome. Entries like "version" sneaked in there because I was using VS to auto-generate local NuGet packages, which made it easier to test with the more complicated config requirements of the SQL sink without actually adding that sink and new sample code to this project. (The transient dependency issue is a real hassle in the .NET Core world where everything is a package now.) |
Fixes #97, adds support for
IConfiguration
parameters,IConfigurationSection
parameters, config-binding of sections by parameter type, and fixes #83, updates MS DependencyModel and Configuration package versions. Probably also addresses #98 though I haven't tested it with arrays specifically. Update: Confirmed, should fix #98.GetSection
never returns null; corrected null-ref tests toGetChildren().Any()
testsAdded>
"hint" character to identify nested configuration sectionsObjectArgumentValue
class to perform config binding and populate config section parametersIConfiguration
parameterUpdated:
ObjectArgumentValue
ConfigurationSectionArgumentValue
IConfiguration
andIConfigurationSection
argumentsList<>
)SQL Sink PR depends on this:
serilog-mssql/serilog-sinks-mssqlserver#120