{"action":"created","issue":{"url":"https://api.github.com/repos/serilog/serilog/issues/402","labels_url":"https://api.github.com/repos/serilog/serilog/issues/402/labels{/name}","comments_url":"https://api.github.com/repos/serilog/serilog/issues/402/comments","events_url":"https://api.github.com/repos/serilog/serilog/issues/402/events","html_url":"https://github.com/serilog/serilog/issues/402","id":60233348,"number":402,"title":"Core `<appSettings>` support","user":{"login":"nblumhardt","id":342712,"avatar_url":"https://avatars.githubusercontent.com/u/342712?v=3","gravatar_id":"","url":"https://api.github.com/users/nblumhardt","html_url":"https://github.com/nblumhardt","followers_url":"https://api.github.com/users/nblumhardt/followers","following_url":"https://api.github.com/users/nblumhardt/following{/other_user}","gists_url":"https://api.github.com/users/nblumhardt/gists{/gist_id}","starred_url":"https://api.github.com/users/nblumhardt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nblumhardt/subscriptions","organizations_url":"https://api.github.com/users/nblumhardt/orgs","repos_url":"https://api.github.com/users/nblumhardt/repos","events_url":"https://api.github.com/users/nblumhardt/events{/privacy}","received_events_url":"https://api.github.com/users/nblumhardt/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/serilog/serilog/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"closed","locked":false,"assignee":{"login":"merbla","id":637298,"avatar_url":"https://avatars.githubusercontent.com/u/637298?v=3","gravatar_id":"","url":"https://api.github.com/users/merbla","html_url":"https://github.com/merbla","followers_url":"https://api.github.com/users/merbla/followers","following_url":"https://api.github.com/users/merbla/following{/other_user}","gists_url":"https://api.github.com/users/merbla/gists{/gist_id}","starred_url":"https://api.github.com/users/merbla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/merbla/subscriptions","organizations_url":"https://api.github.com/users/merbla/orgs","repos_url":"https://api.github.com/users/merbla/repos","events_url":"https://api.github.com/users/merbla/events{/privacy}","received_events_url":"https://api.github.com/users/merbla/received_events","type":"User","site_admin":false},"milestone":null,"comments":3,"created_at":"2015-03-08T00:20:42Z","updated_at":"2015-04-08T22:26:28Z","closed_at":"2015-04-08T22:26:28Z","body":"[Serilog.Extras.AppSettings](http://www.nuget.org/packages/serilog.extras.appsettings) has done very well as a simple XML configuration mechanism. For apps targeting one of the .NET platforms with _Web.config_ or _App.config_ (`System.Configuration`) support there's little reason not to use this approach.\r\n\r\nThe package came in as an \"extra\" because in Serilog 1.0 the role of configuration was still unclear, and the allowable trade-offs not really in focus. For example, was it desirable to have a configuration model that mixed code-provided parameters with ones set in config files, or was either/or acceptable?\r\n\r\nSome experience with _Serilog.Extras.AppSettings_ has cleared up some of these questions, and it's reasonable to move forward in the direction it has set.\r\n\r\nIn the intervening years however, ASP.NET has announced the new \"vNext\"/5.0 version with a new [Configuration subsystem](https://github.com/aspnet/Configuration) that Serilog will also need to support.\r\n\r\nThis ticket outlines how we can get from where we are today, to a simple-but-consistent approach to configuration that Serilog can be prescriptive about.\r\n\r\nSub-tasks:\r\n\r\n - [x] 1. Define a `LoggerConfiguration` extension point for reading external configuration\r\n - [x] 2. Refactor the implementation of `PrefixedAppSettingsReader` so that the process of adding assemblies, discovering extension methods, and calling them, are shared (the shared part will live in _Serilog_)\r\n - [x] 3. Implement the extension point by migrating the code from _Serilog.Extras.AppSettings_ into _Serilog.FullNetFx_\r\n - [x] 4. Remove _Serilog.Extras.AppSettings_ from the main solution, and publish an empty package in its place\r\n - [ ] ~~5. Determine what, if any, internal changes need to be made in order to support JSON values in app settings (see #401)~~\r\n\r\nThe issue is marked \"breaking/v2\" because some incompatible core changes may be considered, but ideally we'd do this in a compatible way so that the changes can ship as Serilog 1.5.\r\n\r\nThe issue's marked \"up-for-grabs\" as it's approachable by anyone with good Serilog knowledge, but it's a SIZABLE chunk of work so please add a note here before kicking it off :-)\r\n\r\n## 1. `LoggerConfiguration` support\r\n\r\nOne of the nice features of Serilog's configuration is its regularity. App setting support currently looks like:\r\n\r\n```csharp\r\nvar log = new LoggerConfiguration()\r\n  .ReadAppSettings()\r\n  .WriteTo.Xyz()\r\n  .CreateLogger();\r\n```\r\n\r\nThe `ReadAppSettings()` call isn't consistent with the majority of configuration syntax and leaves the door open for inconsistencies as additional configuration sources are added.\r\n\r\nAlternative:\r\n\r\n```csharp\r\nvar log = new LoggerConfiguration()\r\n  .ReadFrom.AppSettings()\r\n```\r\n\r\nUsing a dotted syntax makes it easier to find options (type `ReadFrom.` to see supported configuration sources) and sticks with the successful `Verb.Noun()` naming style that seems to have worked well for `WriteTo`.\r\n\r\nThe semantics (immediate invocation of the configuration source against the builder) should stay the same as in the current package.\r\n\r\n## 2. `PrefixedAppSettingsReader` refactor\r\n\r\nThis type discovers configuration methods and maps named arguments onto them. It's likely all configuration mechanisms will do this; we should try to pull out the code from the block at:\r\n\r\nhttps://github.com/serilog/serilog/blob/dev/src/Serilog.Extras.AppSettings/Extras/AppSettings/PrefixedAppSettingsReader.cs#L90\r\n\r\nInto a reusable form.\r\n\r\n## 5. JSON/complex values in settings\r\n\r\nThere's a discussion in #401 about this. There are a couple of ways of approaching support for complex types, e.g. via a direct approach like the one mentioned in the linked issue:\r\n\r\n> 1. If the parameter (in the extension method) is of a known simple type (e.g. `string`, `int`, `DateTime`, ... perhaps `Uri`) then assume the `value='...'` attribute contents are literal values as we do today\r\n> 2. Otherwise, assume the `value='...'` contents are JSON, and attempt to deserialize an instance of the parameter type from it\r\n\r\n> The JSON (de-)serializer would share formatting logic for known simple types like `DateTime` so that the syntax is consistent with (1).\r\n\r\nThis has the advantage of consistency, but might not be universal enough to include in the core. An alternative might be to provide a plug-in point to the `AppSettings` method that can handle deserialization of unknown types:\r\n\r\n```csharp\r\ninterface IAppSettingsValueReader\r\n{\r\n  bool TryRead(Type settingType, string appSettingValue, out object setting);\r\n}\r\n```\r\n\r\nAnd:\r\n\r\n```csharp\r\nvar log = new LoggerConfiguration()\r\n  .ReadFrom.AppSettings(readers: new[] { new JsonValueReader() })\r\n```\r\n\r\nOr embedded in the XML itself, per setting:\r\n\r\n```xml\r\n<add key='serilog:write-to:Email.credentials' value='{\"Username\":...}' />\r\n<add key='serilog:write-to:Email.credentials:reader' value='SomeNamespace.JsonValueReader, ...' />\r\n```\r\n\r\nIt's a bit clunkier than baking something in, but does provide good flexibility and keeps us out of the business of defining yet-another-JSON-parser.\r\n\r\n(@mivano and @Mpdreamz  may have some comments, since they've discussed this in context of the ES sink.)"},"comment":{"url":"https://api.github.com/repos/serilog/serilog/issues/comments/91054182","html_url":"https://github.com/serilog/serilog/issues/402#issuecomment-91054182","issue_url":"https://api.github.com/repos/serilog/serilog/issues/402","id":91054182,"user":{"login":"nblumhardt","id":342712,"avatar_url":"https://avatars.githubusercontent.com/u/342712?v=3","gravatar_id":"","url":"https://api.github.com/users/nblumhardt","html_url":"https://github.com/nblumhardt","followers_url":"https://api.github.com/users/nblumhardt/followers","following_url":"https://api.github.com/users/nblumhardt/following{/other_user}","gists_url":"https://api.github.com/users/nblumhardt/gists{/gist_id}","starred_url":"https://api.github.com/users/nblumhardt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nblumhardt/subscriptions","organizations_url":"https://api.github.com/users/nblumhardt/orgs","repos_url":"https://api.github.com/users/nblumhardt/repos","events_url":"https://api.github.com/users/nblumhardt/events{/privacy}","received_events_url":"https://api.github.com/users/nblumhardt/received_events","type":"User","site_admin":false},"created_at":"2015-04-08T22:26:28Z","updated_at":"2015-04-08T22:26:28Z","body":"@merbla https://github.com/serilog/serilog/pull/422 is on my personal fork; how about I push up the last of the quick changes I have to make and we merge to dev so we can share more of the remainder?"}}