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

Fixes #97, #83, #98 #100

Merged
merged 13 commits into from
Apr 21, 2018
Merged

Fixes #97, #83, #98 #100

merged 13 commits into from
Apr 21, 2018

Conversation

MV10
Copy link
Contributor

@MV10 MV10 commented Apr 19, 2018

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.

  • README updated
  • GetSection never returns null; corrected null-ref tests to GetChildren().Any() tests
  • Added > "hint" character to identify nested configuration sections
  • Added ObjectArgumentValue class to perform config binding and populate config section parameters
  • Added two lines of code just before method invocation to populate an IConfiguration parameter

Updated:

  • Moved nested configuration functionality into ObjectArgumentValue
  • Removed ConfigurationSectionArgumentValue
  • Added unit test for IConfiguration and IConfigurationSection arguments
  • Added unit test for configuration object binding argument (for example, List<>)
  • Added unit tests for string and int array arguments

SQL Sink PR depends on this:
serilog-mssql/serilog-sinks-mssqlserver#120

Copy link
Member

@nblumhardt nblumhardt left a 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the additional docs 👍

Copy link
Contributor Author

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.
Copy link
Member

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 :-)

Copy link
Contributor Author

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.

Copy link
Contributor Author

@MV10 MV10 Apr 20, 2018

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

Copy link
Contributor Author

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
Copy link
Member

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 :-)

Copy link
Contributor Author

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>"" : {
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@MV10 MV10 changed the title Addresses #97 and #83 Addresses #97 and #83 and #98 Apr 20, 2018
@MV10 MV10 changed the title Addresses #97 and #83 and #98 Fixes #97, #83, #98 Apr 20, 2018
@MV10
Copy link
Contributor Author

MV10 commented Apr 20, 2018

@nblumhardt Not sure what happened to our comments about that > hack for marking configuration subsections (I've actually never used the PR-review commenting system before with comments associated with the diffs) ... but in case you don't see those comments now, either:

The hack is gone. Basically I got rid of ConfigurationSectionArgumentValue and rolled that into ObjectArgumentValue. The trick was to start the second pass through ConfigurationReader during method invocation, which lets the class recognize the Action<> argument type, rather than the old way that inferred/assumed based on config structure (or the hint hack).

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>
Copy link
Member

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 👍

@nblumhardt
Copy link
Member

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 nblumhardt merged commit 62acc84 into serilog:dev Apr 21, 2018
@MV10
Copy link
Contributor Author

MV10 commented Apr 22, 2018

@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.)

@MV10 MV10 deleted the iconfig_parameter branch April 22, 2018 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants