{"action":"created","issue":{"url":"https://api.github.com/repos/NLog/NLog/issues/1311","repository_url":"https://api.github.com/repos/NLog/NLog","labels_url":"https://api.github.com/repos/NLog/NLog/issues/1311/labels{/name}","comments_url":"https://api.github.com/repos/NLog/NLog/issues/1311/comments","events_url":"https://api.github.com/repos/NLog/NLog/issues/1311/events","html_url":"https://github.com/NLog/NLog/issues/1311","id":141736028,"number":1311,"title":"Feature request, allow for NLog to render innerexception in formatted JSON","user":{"login":"mccabela","id":13360108,"avatar_url":"https://avatars.githubusercontent.com/u/13360108?v=3","gravatar_id":"","url":"https://api.github.com/users/mccabela","html_url":"https://github.com/mccabela","followers_url":"https://api.github.com/users/mccabela/followers","following_url":"https://api.github.com/users/mccabela/following{/other_user}","gists_url":"https://api.github.com/users/mccabela/gists{/gist_id}","starred_url":"https://api.github.com/users/mccabela/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mccabela/subscriptions","organizations_url":"https://api.github.com/users/mccabela/orgs","repos_url":"https://api.github.com/users/mccabela/repos","events_url":"https://api.github.com/users/mccabela/events{/privacy}","received_events_url":"https://api.github.com/users/mccabela/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/NLog/NLog/labels/feature","name":"feature","color":"02e10c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-03-17T23:42:43Z","updated_at":"2016-03-18T00:05:53Z","closed_at":null,"body":"Feature request for NLog version: 4.2.3\r\n\r\nThe current JSONLayout renderer only supports the rendering of the first exception in fully structured JSON.  I would like to be able to render out all the exceptions, including the inner exceptions, in structured JSON format.\r\n\r\nThis would allow for the separate exceptions to be inspected and allow for a deeper understanding of what happened.\r\n\r\nCurrently you can do something like this:\r\n\r\n```xml\r\n<layout xsi:type=\"JsonLayout\">\r\n          <attribute name=\"datetime\" layout=\"${iso8601dateformat}\" />\r\n          <attribute name=\"level\" layout=\"${level:uppercase=true}\" />\r\n          <attribute name=\"logger\" layout=\"${logger}\" />\r\n          <attribute name=\"thread\" layout=\"${threadid}\" />\r\n          <attribute name=\"machine\" layout=\"${machinename}\" />\r\n          <attribute name=\"message\" layout=\"${message}\" />\r\n          <attribute name=\"exceptions\" encode=\"false\">\r\n            <layout type=\"JsonLayout\">\r\n              <attribute name=\"exception\" encode=\"false\">\r\n                <layout type=\"JsonLayout\">\r\n                  <attribute name=\"message\" layout=\"${exception:format=message}\" />\r\n                  <attribute name=\"stacktrace\" layout=\"${exception:format=stacktrace}\" />\r\n                  <attribute name=\"data\" layout=\"${exception:format=data}\" />\r\n                  <attribute name=\"type\" layout=\"${exception:format=type}\" />\r\n                  <attribute name=\"method\" layout=\"${exception:format=method}\" />\r\n                </layout>\r\n              </attribute>\r\n            </layout>\r\n          </attribute>\r\n        </layout>\r\n```\r\n\r\nWhich will render out something like this:\r\n```js\r\n{\r\n\t\"datetime\": \"2016-03-18T10:28:30.810\",\r\n\t\"level\": \"ERROR\",\r\n\t\"logger\": \"Fairfax.Classifieds.Ore.Company.Business.Controller.Common.ExceptionHandler\",\r\n\t\"thread\": \"82\",\r\n\t\"machine\": \"R5001764W\",\r\n\t\"exceptions\": {\r\n\t\t\"exception\": {\r\n\t\t\t\"message\": \"Check this out\",\r\n\t\t\t\"stacktrace\": \"   at Company.Default.Page_Load(Object sender, EventArgs e) in C:\\\\Source\\\\Company\\\\src\\\\services\\\\Company\\\\Default.aspx.cs:line 20\\r\\n   at System.EventHandler.Invoke(Object sender, EventArgs e)\\r\\n   at System.Web.UI.Control.OnLoad(EventArgs e)\\r\\n   at System.Web.UI.Control.LoadRecursive()\\r\\n   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)\",\r\n\t\t\t\"type\": \"System.ApplicationException\",\r\n\t\t\t\"method\": \"Void Page_Load(System.Object, System.EventArgs)\"\r\n\t\t}\r\n\t},\r\n}\r\n```\r\n\r\nI would like to be able to render out is something like this:\r\n\r\n```js\r\n{\r\n\t\"datetime\": \"2016-03-18T10:28:30.810\",\r\n\t\"level\": \"ERROR\",\r\n\t\"logger\": \"Fairfax.Classifieds.Ore.Company.Business.Controller.Common.ExceptionHandler\",\r\n\t\"thread\": \"82\",\r\n\t\"machine\": \"R5001764W\",\r\n\t\"exceptions\": {\r\n\t\t\"exception\": {\r\n\t\t\t\"message\": \"Check this out\",\r\n\t\t\t\"stacktrace\": \"   at Company.Default.Page_Load(Object sender, EventArgs e) in C:\\\\Source\\\\Company\\\\src\\\\services\\\\Company\\\\Default.aspx.cs:line 20\\r\\n   at System.EventHandler.Invoke(Object sender, EventArgs e)\\r\\n   at System.Web.UI.Control.OnLoad(EventArgs e)\\r\\n   at System.Web.UI.Control.LoadRecursive()\\r\\n   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)\",\r\n\t\t\t\"type\": \"System.ApplicationException\",\r\n\t\t\t\"method\": \"Void Page_Load(System.Object, System.EventArgs)\"\r\n\t\t},\r\n\t\t\"exception\": {\r\n\t\t\t\"message\": \"Inner Exception 1\",\r\n\t\t\t\"stacktrace\": \"   at Company.Default.Method1(Object sender, EventArgs e) in C:\\\\Source\\\\Company\\\\src\\\\services\\\\Company\\\\Default.aspx.cs:line 20\\r\\n   at System.EventHandler.Invoke(Object sender, EventArgs e)\\r\\n   at System.Web.UI.Control.OnLoad(EventArgs e)\\r\\n   at System.Web.UI.Control.LoadRecursive()\\r\\n   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)\",\r\n\t\t\t\"type\": \"System.InvalidOperationException\",\r\n\t\t\t\"method\": \"Void Method1(System.Object, System.EventArgs)\"\r\n\t\t}\r\n\t},\r\n}\r\n```\r\n\r\nI have a technical background so I'm happy to help implement but would like some guidance on architecturally how this can be best achieved.\r\n\r\nMany thanks,\r\n\r\nLach"},"comment":{"url":"https://api.github.com/repos/NLog/NLog/issues/comments/198139095","html_url":"https://github.com/NLog/NLog/issues/1311#issuecomment-198139095","issue_url":"https://api.github.com/repos/NLog/NLog/issues/1311","id":198139095,"user":{"login":"mccabela","id":13360108,"avatar_url":"https://avatars.githubusercontent.com/u/13360108?v=3","gravatar_id":"","url":"https://api.github.com/users/mccabela","html_url":"https://github.com/mccabela","followers_url":"https://api.github.com/users/mccabela/followers","following_url":"https://api.github.com/users/mccabela/following{/other_user}","gists_url":"https://api.github.com/users/mccabela/gists{/gist_id}","starred_url":"https://api.github.com/users/mccabela/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mccabela/subscriptions","organizations_url":"https://api.github.com/users/mccabela/orgs","repos_url":"https://api.github.com/users/mccabela/repos","events_url":"https://api.github.com/users/mccabela/events{/privacy}","received_events_url":"https://api.github.com/users/mccabela/received_events","type":"User","site_admin":false},"created_at":"2016-03-18T00:05:53Z","updated_at":"2016-03-18T00:05:53Z","body":"Actually Maybe a structure like this would be better?\r\n\r\n```js\r\n{\r\n\t\"exception\": {\r\n\t\t\"message\": \"Check this out\",\r\n\t\t\"stacktrace\": \"   at Company.Default.Page_Load(Object sender, EventArgs e) in C:\\\\Source\\\\Company\\\\src\\\\services\\\\Company\\\\Default.aspx.cs:line 20\\r\\n   at System.EventHandler.Invoke(Object sender, EventArgs e)\\r\\n   at System.Web.UI.Control.OnLoad(EventArgs e)\\r\\n   at System.Web.UI.Control.LoadRecursive()\\r\\n   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)\",\r\n\t\t\"type\": \"System.ApplicationException\",\r\n\t\t\"method\": \"Void Page_Load(System.Object, System.EventArgs)\",\r\n\t\t\"innerException\": {\r\n\t\t\t\"message\": \"Inner Exception 1\",\r\n\t\t\t\"stacktrace\": \"   at Company.Default.Method1(Object sender, EventArgs e) in C:\\\\Source\\\\Company\\\\src\\\\services\\\\Company\\\\Default.aspx.cs:line 20\\r\\n   at System.EventHandler.Invoke(Object sender, EventArgs e)\\r\\n   at System.Web.UI.Control.OnLoad(EventArgs e)\\r\\n   at System.Web.UI.Control.LoadRecursive()\\r\\n   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)\",\r\n\t\t\t\"type\": \"System.InvalidOperationException\",\r\n\t\t\t\"method\": \"Void Method1(System.Object, System.EventArgs)\",\r\n\t\t\t\"innerException\": {\r\n\t\t\t\t\"message\": \"Inner Exception 2\",\r\n\t\t\t\t\"stacktrace\": \"   at Company.Default.Method1(Object sender, EventArgs e) in C:\\\\Source\\\\Company\\\\src\\\\services\\\\Company\\\\Default.aspx.cs:line 20\\r\\n   at System.EventHandler.Invoke(Object sender, EventArgs e)\\r\\n   at System.Web.UI.Control.OnLoad(EventArgs e)\\r\\n   at System.Web.UI.Control.LoadRecursive()\\r\\n   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)\",\r\n\t\t\t\t\"type\": \"System.InvalidOperationException\",\r\n\t\t\t\t\"method\": \"Void Method1(System.Object, System.EventArgs)\"\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\nand maybe using something like this?\r\n\r\n```xml\r\n\r\n          <attribute name=\"exception\" encode=\"false\">\r\n            <layout type=\"JsonNestedExceptionLayout\" source=\"${exception}\" maxInnerExceptionLevel=\"5\">\r\n                  <attribute name=\"message\" layout=\"${exception:format=message}\" />\r\n                  <attribute name=\"stacktrace\" layout=\"${exception:format=stacktrace}\" />\r\n                  <attribute name=\"data\" layout=\"${exception:format=data}\" />\r\n                  <attribute name=\"type\" layout=\"${exception:format=type}\" />\r\n                  <attribute name=\"method\" layout=\"${exception:format=method}\" />\r\n                  <attribute name=\"innerException\" layout=\"${exception:innerexception}\" />\r\n            </layout>\r\n          </attribute>\r\n```"}}