{"action":"created","issue":{"url":"https://api.github.com/repos/serilog/serilog/issues/1127","repository_url":"https://api.github.com/repos/serilog/serilog","labels_url":"https://api.github.com/repos/serilog/serilog/issues/1127/labels{/name}","comments_url":"https://api.github.com/repos/serilog/serilog/issues/1127/comments","events_url":"https://api.github.com/repos/serilog/serilog/issues/1127/events","html_url":"https://github.com/serilog/serilog/issues/1127","id":302985789,"number":1127,"title":"Serilog fails to log JSON object with empty-string properties","user":{"login":"andrewslavin","id":6835786,"avatar_url":"https://avatars2.githubusercontent.com/u/6835786?v=4","gravatar_id":"","url":"https://api.github.com/users/andrewslavin","html_url":"https://github.com/andrewslavin","followers_url":"https://api.github.com/users/andrewslavin/followers","following_url":"https://api.github.com/users/andrewslavin/following{/other_user}","gists_url":"https://api.github.com/users/andrewslavin/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewslavin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewslavin/subscriptions","organizations_url":"https://api.github.com/users/andrewslavin/orgs","repos_url":"https://api.github.com/users/andrewslavin/repos","events_url":"https://api.github.com/users/andrewslavin/events{/privacy}","received_events_url":"https://api.github.com/users/andrewslavin/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-07T07:00:11Z","updated_at":"2018-03-07T21:16:24Z","closed_at":"2018-03-07T21:16:24Z","author_association":"NONE","body":"I use Serilog.AspNetCore in Asp.Net Core 2.0 web api project. I also use Destructurama.JsonNet to log JSON objects as structured data. Now here's the issue:\r\n\r\n1. If you send a POST request with empty body to an Asp.Net Core 2.0 web api endpoint, it will reply with a 400 response. Content-type is `application/json`, and body is `{\"\":[\"A non-empty request body is required.\"]}`.\r\n1. I log requests to and responses from my api. When I log this particular response, I can see that content-type is JSON, so I read the body to string and then deserialize it using `Newtonsoft.Json.JsonConvert.DeserializeObject()`.\r\n1. Then I log the result of deserialization with Serilog, and get an exception\r\n```\r\nSystem.ArgumentException: Property name is not valid.\r\n   at Serilog.Events.LogEventProperty..ctor(String name, LogEventPropertyValue value)\r\n   at Destructurama.JsonNet.JsonNetDestructuringPolicy.Destructure(JObject jo, ILogEventPropertyValueFactory propertyValueFactory)\r\n   at Destructurama.JsonNet.JsonNetDestructuringPolicy.TryDestructure(Object value, ILogEventPropertyValueFactory propertyValueFactory, LogEventPropertyValue& result)\r\n   at Serilog.Capturing.PropertyValueConverter.CreatePropertyValue(Object value, Destructuring destructuring, Int32 depth)\r\n   at Serilog.Capturing.PropertyValueConverter.DepthLimiter.CreatePropertyValue(Object value, Destructuring destructuring)\r\n   at Serilog.Capturing.PropertyValueConverter.<<TryConvertEnumerable>g__MapToDictionaryElements14_0>d.MoveNext()\r\n   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)\r\n   at Serilog.Events.DictionaryValue..ctor(IEnumerable`1 elements)\r\n   at Serilog.Capturing.PropertyValueConverter.TryConvertEnumerable(Object value, Destructuring destructuring, Type valueType, LogEventPropertyValue& result)\r\n   at Serilog.Capturing.PropertyValueConverter.CreatePropertyValue(Object value, Destructuring destructuring, Int32 depth)\r\n   at Serilog.Core.Logger.BindProperty(String propertyName, Object value, Boolean destructureObjects, LogEventProperty& property)\r\n   at Serilog.Extensions.Logging.SerilogLogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)\r\n   at Microsoft.Extensions.Logging.Logger`1.Microsoft.Extensions.Logging.ILogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)\r\n   at Microsoft.Extensions.Logging.LoggerExtensions.LogDebug(ILogger logger, String message, Object[] args)\r\n   at ... my code here ...\r\n```\r\n\r\nI can see the exception is being thrown here [https://github.com/serilog/serilog/blob/32e0c9578db720add74720bceb62bd46967694c4/src/Serilog/Events/LogEventProperty.cs](url), because empty string JSON property name does not pass the `IsValidName(string name)` validation. Is it possible to remove this validation and allow any name string? `JsonConvert.DeserializeObject()` does not complain about empty string property names."},"comment":{"url":"https://api.github.com/repos/serilog/serilog/issues/comments/371287426","html_url":"https://github.com/serilog/serilog/issues/1127#issuecomment-371287426","issue_url":"https://api.github.com/repos/serilog/serilog/issues/1127","id":371287426,"user":{"login":"nblumhardt","id":342712,"avatar_url":"https://avatars2.githubusercontent.com/u/342712?v=4","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":"2018-03-07T21:16:24Z","updated_at":"2018-03-07T21:16:24Z","author_association":"OWNER","body":"Hi @andrewslavin - thanks for the report!\r\n\r\nI think the bug here is with `Destructurama.JsonNet` - when a JSON object has an empty-string key, it needs to be logged through Serilog as a `DictionaryValue` instead of as a `StructureValue`. Removing the constraint on structure member names being non-empty could break other components downstream.\r\n\r\nAny help over on the Destructurama side appreciated! I'll move the issue over there."}}
{"actor":{"display_login":"nblumhardt"}}