-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Support JSON with objects (not only flat key-value) #723
Comments
note: the proposal isn't a JSON array, but a JSON object. |
Ah, you're right. Of course it is. My mistake. |
This is difficult issue, because the JSONlayout isn't aware of the Any idea how we could solve this? |
I can imagine three ways of doing this. The dirtiest but easiest version would be to allow a parameter <attribute name="properties" layout="${all-event-properties}" raw /> A cleaner (but quite limited) alternative would be to recognize that some layout renderers (such as <attributes name="properties" layout="${event-properties}" each="item" /> At the layout renderer level, a new function would be required to enumerate those values: [EnumerableParameter]
[RequiredParameter]
public string Item { get; set; }
public override IEnumerable<string> GetEach(string which, LogEventInfo logEvent)
{
if (which == "Item")
// enumerate all possible values of "Item", based on the values provided
// for the other parameters
else
throw new ArgumentException("Not enumerable: " + which, "which");
} Thus, The cleanest would be to allow renderers to return a certain number of non-string types, including JSON ones (arrays, dictionaries) but also non-JSON ( |
Thanks! I will think about these proposals. |
I was looking into this item and in my opinion the first solution looks more clean as well as matching other formatting layouts which we already have in place. For Eampple we specify "toString", "mm/dd/yyyy" for dates. |
Thanks Sree, Yes I like that one also the best one. But do we need the |
@304NotModified I am not sure how the raw attribute will be used with toJSON formatting. What I was thinking is if the format is set to toJSON, then we can render as depicted in the initial comment of this ticket. For Serialization following comes to my mind.
|
Do any one have any other suggestions on this? |
note to others: this has been discussed on the dev chat. The proposal of @page-not-found by including the javascript serializer code from coreFX is the best one :) So we will implement this in NLog core (not web). No need for dependency injection now |
@page-not-found are you still working on this? I would to release this in 4.3 (1-2 weeks from now) |
Yes was working in this, but did not find time. May be we can think this
|
@304NotModified Do you think other wise? I am in middle of the implementation, trying to get the the unit testing completed. |
@page-not-found any success on this? |
With the way it is done right now. It is getting tough to put in any new @page-not-found https://github.com/Page-Not-Found any success on this? — |
Well you can PR it and we can review it of course. Not problem that it's WIP. If you write 1 unit test, then we can easily create more. |
I will try to get this out this week.
|
Cool :) |
I am making some progress here. Would be able to get some base beta version my upcoming week. Sorry I am keep extending the time, is because with the current code it is getting harder to add additional things to one area without affecting others. |
This is supported by nesting JsonLayouts. See https://github.com/NLog/NLog/wiki/JsonLayout#advanced-examples |
Hi @304NotModified, How can I achieve that with the Thanks ;) |
This is solved in two ways:
Too bad, the all-event-properties isn't aware of JSON, so it's printing a (non-JSON) string. We like to fix this, but we need an approach which works for (almost) every layout renderer. If you think this is needed/desired, please create a new issue. :) |
Thanks. I think it's very useful features, especially if you have a log management solution :) (I'm coming from Logmatic.io ^^) I don't know .Net to be honest but I will check how can we handle that. |
I don't see how this is supported by JsonNestingLayouts, and the example in the link doesn't address the situation very well. The example specifies an exception, that has two well-known properties, not a dynamic list of key-value pairs of type string, object. Can we either A) update the documentation with an example of how to make this work, or B) reopen this issue? |
Please open a new issue on github or (preferred) stackoverflow. |
Ah, I now fully understand your question, There is a new option e.g. <target xsi:type="ColoredConsole" name="coloredConsole">
<layout xsi:type="JsonLayout" includeAllProperties="true">
<attribute name="timestamp" layout="${longdate}"/>
<attribute name="level" layout="${level:uppercase=true}"/>
<attribute name="exception" layout="${onexception:${exception:format=tostring}}" />
</layout>
</target>
You could also skip some properties with |
also posted on StackOverflow |
I'm still getting this sort of thing:
it's basically taking the object and doing |
Unfortunately, it was thinking that was fixed already. |
We have a ijsonserializer, that one should be used |
Thanks |
@jholovacs created a new issue for it. #2127 |
Version: NLog 4.0 RC
From this post:
This configuration
Generates this. Notice
properties
Instead of a key value string, create a JSON array.
Maybe this is also needed for other event properties?
The text was updated successfully, but these errors were encountered: